summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEiichi Sato <eiichi.for.public@gmail.com>2010-04-10 01:52:10 +0900
committerEmmanuele Bassi <ebassi@linux.intel.com>2010-04-15 10:16:43 +0100
commit3046a0222e73a3da2d87eb088302de45e2846aa0 (patch)
treefb0e30a0128b73b134319d03026cbb131bf837d4
parentb60a8c2d57acb25c6fcffb45d34ba6422cee043e (diff)
downloadjson-glib-3046a0222e73a3da2d87eb088302de45e2846aa0.tar.gz
Support for surrogate pairs in json string.
https://bugzilla.gnome.org/show_bug.cgi?id=615799 (cherry picked from commit fcd07918d3ed2b31b047900da9d2fed23dddf7da) Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
-rw-r--r--json-glib/json-scanner.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/json-glib/json-scanner.c b/json-glib/json-scanner.c
index 9cd0938..6eca2ba 100644
--- a/json-glib/json-scanner.c
+++ b/json-glib/json-scanner.c
@@ -892,7 +892,7 @@ json_scanner_get_unichar (JsonScanner *scanner,
break;
}
- g_assert (g_unichar_validate (uchar));
+ g_assert (g_unichar_validate (uchar) || g_unichar_type (uchar) == G_UNICODE_SURROGATE);
return uchar;
}
@@ -1439,6 +1439,20 @@ json_scanner_get_token_ll (JsonScanner *scanner,
gunichar ucs;
ucs = json_scanner_get_unichar (scanner, line_p, position_p);
+
+ if (g_unichar_type (ucs) == G_UNICODE_SURROGATE)
+ {
+ /* read next surrogate */
+ if ('\\' == json_scanner_get_char (scanner, line_p, position_p)
+ && 'u' == json_scanner_get_char (scanner, line_p, position_p))
+ {
+ gunichar ucs_lo = json_scanner_get_unichar (scanner, line_p, position_p);
+ g_assert (g_unichar_type (ucs_lo) == G_UNICODE_SURROGATE);
+ ucs = (((ucs & 0x3ff) << 10) | (ucs_lo & 0x3ff)) + 0x10000;
+ }
+ }
+
+ g_assert (g_unichar_validate (ucs));
gstring = g_string_append_unichar (gstring, ucs);
}
break;