diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2010-11-16 02:07:52 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2010-11-16 02:07:52 +0000 |
commit | f24610c8c3adac2f955ead2b1992295f90244816 (patch) | |
tree | 5138c9d247a776190d42e460a22c50d8e4cbdd03 /libsylph | |
parent | 656a2a821b26760ac023220bb8c7a982de05be61 (diff) |
libsylph/xml.[ch]: xml_escape_str(): added.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2721 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph')
-rw-r--r-- | libsylph/xml.c | 35 | ||||
-rw-r--r-- | libsylph/xml.h | 1 |
2 files changed, 36 insertions, 0 deletions
diff --git a/libsylph/xml.c b/libsylph/xml.c index 9f4c4257..23b98506 100644 --- a/libsylph/xml.c +++ b/libsylph/xml.c @@ -520,6 +520,41 @@ gint xml_unescape_str(gchar *str) return 0; } +gchar *xml_escape_str(const gchar *str) +{ + GString *estr; + const gchar *p; + + if (!str) + return NULL; + + estr = g_string_sized_new(strlen(str)); + for (p = str; *p != '\0'; p++) { + switch (*p) { + case '<': + g_string_append(estr, "<"); + break; + case '>': + g_string_append(estr, ">"); + break; + case '&': + g_string_append(estr, "&"); + break; + case '\'': + g_string_append(estr, "'"); + break; + case '\"': + g_string_append(estr, """); + break; + default: + g_string_append_c(estr, *p); + break; + } + } + + return g_string_free(estr, FALSE); +} + gint xml_file_put_escape_str(FILE *fp, const gchar *str) { const gchar *p; diff --git a/libsylph/xml.h b/libsylph/xml.h index 95a61ac1..766281b6 100644 --- a/libsylph/xml.h +++ b/libsylph/xml.h @@ -95,6 +95,7 @@ XMLTag *xml_copy_tag (XMLTag *tag); XMLAttr *xml_copy_attr (XMLAttr *attr); gint xml_unescape_str (gchar *str); +gchar *xml_escape_str (const gchar *str); gint xml_file_put_escape_str (FILE *fp, const gchar *str); |