summaryrefslogtreecommitdiff
path: root/gdata/gdata-parser.c
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2010-01-25 15:15:08 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2010-01-25 15:15:08 +0000
commitafd50ddc91bcd4a9cb1da17181f1f2e6658eb0ec (patch)
tree169e1c3f9daf9adae320f4403ace24d75240678d /gdata/gdata-parser.c
parent62fafe938a1dd03d763de1068d69495b3e219ba4 (diff)
downloadlibgdata-afd50ddc91bcd4a9cb1da17181f1f2e6658eb0ec.tar.gz
[gd] Make string parsing UTF-8–safe
Make the various small bits of string parsing/handling (which all occur in the GData code) UTF-8 safe, and add some test cases.
Diffstat (limited to 'gdata/gdata-parser.c')
-rw-r--r--gdata/gdata-parser.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/gdata/gdata-parser.c b/gdata/gdata-parser.c
index c58bcba0..7f13761f 100644
--- a/gdata/gdata-parser.c
+++ b/gdata/gdata-parser.c
@@ -271,3 +271,25 @@ gdata_parser_string_append_escaped (GString *xml_string, const gchar *pre, const
if (post != NULL)
g_string_append (xml_string, post);
}
+
+gchar *
+gdata_parser_utf8_trim_whitespace (const gchar *s)
+{
+ glong len;
+ const gchar *_s;
+
+ /* Skip the leading whitespace */
+ while (*s != '\0' && g_unichar_isspace (g_utf8_get_char (s)))
+ s = g_utf8_next_char (s);
+
+ /* Find the end of the string and backtrack until we've passed all the whitespace */
+ len = g_utf8_strlen (s, -1);
+ _s = g_utf8_offset_to_pointer (s, len - 1);
+ while (len > 0 && g_unichar_isspace (g_utf8_get_char (_s))) {
+ _s = g_utf8_prev_char (_s);
+ len--;
+ }
+ _s = g_utf8_next_char (_s);
+
+ return g_strndup (s, _s - s);
+}