diff options
author | Damien George <damien.p.george@gmail.com> | 2014-09-21 23:28:40 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-09-21 23:43:03 +0100 |
commit | df1e92ba3a039738b65486ebbd4428b7740d723d (patch) | |
tree | bed0a1f045b7738ae7ac5b7d9eab8bdaffae9dce /extmod/modujson.c | |
parent | fa2f1f72e0cb6f3ddb04d52719bad4c2ae7c836a (diff) |
extmod, ujson: Add \uxxxx parsing in json strings.
Diffstat (limited to 'extmod/modujson.c')
-rw-r--r-- | extmod/modujson.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/extmod/modujson.c b/extmod/modujson.c index eaee57c5b..370555249 100644 --- a/extmod/modujson.c +++ b/extmod/modujson.c @@ -100,7 +100,7 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) { break; case '"': vstr_reset(&vstr); - for (s++; s < top && *s != '"'; s++) { + for (s++; s < top && *s != '"';) { byte c = *s; if (c == '\\') { s++; @@ -111,10 +111,24 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) { case 'n': c = 0x0a; break; case 'r': c = 0x0d; break; case 't': c = 0x09; break; - case 'u': if (s + 4 >= top) { goto fail; } else { assert(0); } //vstr_add_char(&vstr, s[0] + case 'u': { + if (s + 4 >= top) { goto fail; } + mp_uint_t num = 0; + for (int i = 0; i < 4; i++) { + c = (*++s | 0x20) - '0'; + if (c > 9) { + c -= ('a' - ('9' + 1)); + } + num = (num << 4) | c; + } + vstr_add_char(&vstr, num); + goto str_cont; + } } } vstr_add_byte(&vstr, c); + str_cont: + s++; } if (s == top) { goto fail; |