From e7184989ec97fc24cfd62efb4eb73045acfbfd77 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 5 Feb 2014 21:42:49 -0800 Subject: [PATCH] Handle \u escapes in strings --- jsonpull.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/jsonpull.c b/jsonpull.c index d074585..15552ae 100644 --- a/jsonpull.c +++ b/jsonpull.c @@ -278,7 +278,22 @@ json_object *json_parse(FILE *f, json_object *current) { } else if (c == 't') { string_append(&val, '\t'); } else if (c == 'u') { - /* XXX */ + char hex[5] = "aaaa"; + int i; + for (i = 0; i < 4; i++) { + hex[i] = getc(f); + } + unsigned long ch = strtoul(hex, NULL, 16); + if (ch <= 0x7F) { + string_append(&val, ch); + } else if (ch <= 0x7FF) { + string_append(&val, 0xC0 | (ch >> 6)); + string_append(&val, 0x80 | (ch & 0x3F)); + } else { + string_append(&val, 0xE0 | (ch >> 12)); + string_append(&val, 0x80 | ((ch >> 6) & 0x3F)); + string_append(&val, 0x80 | (ch & 0x3F)); + } } else { json_error("unknown string escape %c\n", c); }