From e8161ec5bf893d935148fe48925d1315f3aab949 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 1 Dec 2012 12:13:44 +0000 Subject: Importing json.c UTF-8 encoding fix from upstream. Not importing the strto(d|l) fix because I can just use GLib instead of reinventing the wheel. This should fix corruption issues with tweets in Cyrillic. I've double- checked this code against http://en.wikipedia.org/wiki/UTF-8 now and it looks correct to me. --- lib/json.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/json.c') diff --git a/lib/json.c b/lib/json.c index 5cc18fad..52e22d0e 100644 --- a/lib/json.c +++ b/lib/json.c @@ -42,6 +42,7 @@ const struct _json_value json_value_none = { 0 }; #endif +#include #include #include #include @@ -286,7 +287,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch if (state.first_pass) string_length += 2; else - { string [string_length ++] = 0xC0 | ((uc_b2 & 0xC0) >> 6) | ((uc_b1 & 0x3) << 3); + { string [string_length ++] = 0xC0 | ((uc_b2 & 0xC0) >> 6) | ((uc_b1 & 0x7) << 2); string [string_length ++] = 0x80 | (uc_b2 & 0x3F); } @@ -482,9 +483,9 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch continue; if (top->type == json_double) - top->u.dbl = strtod (i, (json_char **) &i); + top->u.dbl = g_ascii_strtod (i, (json_char **) &i); else - top->u.integer = strtoll (i, (json_char **) &i, 10); + top->u.integer = g_ascii_strtoll (i, (json_char **) &i, 10); flags |= flag_next | flag_reproc; } -- cgit v1.2.3