Support for \u sequences in JSON

This commit is contained in:
Ekaitz Zarraga 2020-05-18 22:31:49 +02:00
parent 62efe38c70
commit c448e8b441

View file

@ -57,6 +57,7 @@ sexp parse_json_literal (sexp ctx, sexp self, sexp str, const char* s, int* i, c
sexp parse_json_string (sexp ctx, sexp self, sexp str, const char* s, int* i, const int len) { sexp parse_json_string (sexp ctx, sexp self, sexp str, const char* s, int* i, const int len) {
sexp_gc_var2(res, tmp); sexp_gc_var2(res, tmp);
sexp_gc_preserve2(ctx, res, tmp); sexp_gc_preserve2(ctx, res, tmp);
char utf_tmp[5];
int from = *i, to = *i; int from = *i, to = *i;
res = SEXP_NULL; res = SEXP_NULL;
for ( ; s[to] != '"'; ++to) { for ( ; s[to] != '"'; ++to) {
@ -78,6 +79,12 @@ sexp parse_json_string (sexp ctx, sexp self, sexp str, const char* s, int* i, co
res = sexp_cons(ctx, tmp, res); res = sexp_cons(ctx, tmp, res);
from = to+1; from = to+1;
break; break;
case 'u':
strncpy(utf_tmp, s+to+1, 5);
tmp = sexp_make_string(ctx, sexp_make_fixnum(1), sexp_make_character(strtoll(utf_tmp, NULL, 16)));
res = sexp_cons(ctx, tmp, res);
from = to+5;
break;
default: default:
from = to; from = to;
break; break;