From c448e8b44107bb45aca1a81b085de791ad14ceda Mon Sep 17 00:00:00 2001
From: Ekaitz Zarraga <ekaitz@elenq.tech>
Date: Mon, 18 May 2020 22:31:49 +0200
Subject: [PATCH] Support for \u sequences in JSON

---
 lib/chibi/json.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/chibi/json.c b/lib/chibi/json.c
index 90e915b4..30834c24 100644
--- a/lib/chibi/json.c
+++ b/lib/chibi/json.c
@@ -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_gc_var2(res, tmp);
   sexp_gc_preserve2(ctx, res, tmp);
+  char utf_tmp[5];
   int from = *i, to = *i;
   res = SEXP_NULL;
   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);
         from = to+1;
         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:
         from = to;
         break;