aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--epan/strutil.c41
-rw-r--r--epan/strutil.h3
2 files changed, 42 insertions, 2 deletions
diff --git a/epan/strutil.c b/epan/strutil.c
index 31c288aae0..bbf5f1b941 100644
--- a/epan/strutil.c
+++ b/epan/strutil.c
@@ -1,7 +1,7 @@
/* strutil.c
* String utility routines
*
- * $Id: strutil.c,v 1.18 2004/02/05 09:42:26 guy Exp $
+ * $Id: strutil.c,v 1.19 2004/05/01 20:46:24 obiot Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -397,6 +397,45 @@ hex_str_to_bytes(const char *hex_str, GByteArray *bytes) {
}
+/* Return a XML escaped representation of the unescaped string.
+ * The returned string must be freed when no longer in use. */
+gchar *
+xml_escape(const gchar *unescaped)
+{
+ GString *buffer = g_string_sized_new(128);
+ const gchar *p;
+ gchar c;
+
+ p = unescaped;
+ while ( (c = *p++) ) {
+ switch (c) {
+ case '<':
+ g_string_append(buffer, "&lt;");
+ break;
+ case '>':
+ g_string_append(buffer, "&gt;");
+ break;
+ case '&':
+ g_string_append(buffer, "&amp;");
+ break;
+ case '\'':
+ g_string_append(buffer, "&apos;");
+ break;
+ case '"':
+ g_string_append(buffer, "&quot;");
+ break;
+ default:
+ g_string_append_c(buffer, c);
+ break;
+ }
+ }
+ /* Return the string value contained within the GString
+ * after getting rid of the GString structure.
+ * This is the way to do this, see the GLib reference. */
+ return g_string_free(buffer, FALSE);
+}
+
+
/* Return the first occurrence of needle in haystack.
* If not found, return NULL.
* If either haystack or needle has 0 length, return NULL.
diff --git a/epan/strutil.h b/epan/strutil.h
index a90c294646..f78b5a7c0e 100644
--- a/epan/strutil.h
+++ b/epan/strutil.h
@@ -1,7 +1,7 @@
/* strutil.h
* String utility definitions
*
- * $Id: strutil.h,v 1.14 2004/01/25 16:58:25 jmayer Exp $
+ * $Id: strutil.h,v 1.15 2004/05/01 20:46:24 obiot Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -35,6 +35,7 @@ gchar* format_text(const guchar *line, int len);
gchar* bytes_to_str(const guint8 *, int);
gchar* bytes_to_str_punct(const guint8 *, int, gchar punct);
gboolean hex_str_to_bytes(const char *hex_str, GByteArray *bytes);
+gchar* xml_escape(const gchar *unescaped);
const guint8 * epan_memmem(const guint8 *haystack, guint haystack_len,
const guint8 *needle, guint needle_len);