From 0b69c9abe1465c49371b9192262c44aefecbe190 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 20 Sep 2022 07:21:47 +0200 Subject: [PATCH] Added support for bigger codepoints in xs_utf8_enc(). --- xs_encdec.h | 7 +++++++ xs_json.h | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/xs_encdec.h b/xs_encdec.h index e336218..1ca9346 100644 --- a/xs_encdec.h +++ b/xs_encdec.h @@ -171,6 +171,13 @@ d_char *xs_utf8_enc(d_char *str, unsigned int cpoint) tmp[n++] = 0x80 | ((cpoint >> 6) & 0x3f); tmp[n++] = 0x80 | (cpoint & 0x3f); } + else + if (cpoint < 0x200000) { + tmp[n++] = 0xf0 | (cpoint >> 18); + tmp[n++] = 0x80 | ((cpoint >> 12) & 0x3f); + tmp[n++] = 0x80 | ((cpoint >> 6) & 0x3f); + tmp[n++] = 0x80 | (cpoint & 0x3f); + } return xs_append_m(str, (char *)tmp, n); } diff --git a/xs_json.h b/xs_json.h index 75a4e4d..53b1d20 100644 --- a/xs_json.h +++ b/xs_json.h @@ -244,7 +244,6 @@ d_char *_xs_json_loads_lexer(const char **json, js_type *t) s += 3; tmp[4] = '\0'; - xs_debug(); sscanf(tmp, "%04x", &i); if (i >= 0xd800 && i <= 0xdfff) {