mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Backport from xs.
This commit is contained in:
parent
08e43f2093
commit
59b049fe3b
2 changed files with 26 additions and 7 deletions
31
xs_json.h
31
xs_json.h
|
@ -238,20 +238,39 @@ static xs_val *_xs_json_loads_lexer(const char **json, js_type *t)
|
||||||
case 't': c = '\t'; break;
|
case 't': c = '\t'; break;
|
||||||
case 'u': /* Unicode codepoint as an hex char */
|
case 'u': /* Unicode codepoint as an hex char */
|
||||||
s++;
|
s++;
|
||||||
memcpy(tmp, s, 4);
|
strncpy(tmp, s, 4);
|
||||||
s += 3;
|
|
||||||
tmp[4] = '\0';
|
tmp[4] = '\0';
|
||||||
|
|
||||||
|
if (strlen(tmp) != 4) {
|
||||||
|
*t = JS_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
s += 3; /* skip as it was one byte */
|
||||||
|
|
||||||
sscanf(tmp, "%04x", &i);
|
sscanf(tmp, "%04x", &i);
|
||||||
|
|
||||||
if (i >= 0xd800 && i <= 0xdfff) {
|
if (i >= 0xd800 && i <= 0xdfff) {
|
||||||
/* it's a surrogate pair */
|
/* it's a surrogate pair */
|
||||||
cp = (i & 0x3ff) << 10;
|
cp = (i & 0x3ff) << 10;
|
||||||
|
|
||||||
/* skip to the next value */
|
/* skip to the next value (last char + \ + u) */
|
||||||
s += 3;
|
s++;
|
||||||
memcpy(tmp, s, 4);
|
if (memcmp(s, "\\u", 2) != 0) {
|
||||||
s += 3;
|
*t = JS_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
s += 2;
|
||||||
|
|
||||||
|
strncpy(tmp, s, 4);
|
||||||
|
tmp[4] = '\0';
|
||||||
|
|
||||||
|
if (strlen(tmp) != 4) {
|
||||||
|
*t = JS_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
s += 3; /* skip as it was one byte */
|
||||||
|
|
||||||
sscanf(tmp, "%04x", &i);
|
sscanf(tmp, "%04x", &i);
|
||||||
cp |= (i & 0x3ff);
|
cp |= (i & 0x3ff);
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
/* 333e84c76cd0e51f9f98a36df2eb3bf81e0d2608 */
|
/* 494e346f92431041350f72431417eee03a23eafd */
|
||||||
|
|
Loading…
Reference in a new issue