summaryrefslogtreecommitdiff
path: root/xs_json.h
diff options
context:
space:
mode:
Diffstat (limited to 'xs_json.h')
-rw-r--r--xs_json.h12
1 files changed, 4 insertions, 8 deletions
diff --git a/xs_json.h b/xs_json.h
index e9dc052..03f7903 100644
--- a/xs_json.h
+++ b/xs_json.h
@@ -248,24 +248,20 @@ static xs_val *_xs_json_load_lexer(FILE *f, js_type *t)
break;
}
- if (cp >= 0xd800 && cp <= 0xdfff) {
- /* it's a surrogate pair */
- cp = (cp & 0x3ff) << 10;
-
+ if (xs_is_surrogate(cp)) {
/* \u must follow */
if (fgetc(f) != '\\' || fgetc(f) != 'u') {
*t = JS_ERROR;
break;
}
- unsigned int i;
- if (fscanf(f, "%04x", &i) != 1) {
+ unsigned int p2;
+ if (fscanf(f, "%04x", &p2) != 1) {
*t = JS_ERROR;
break;
}
- cp |= (i & 0x3ff);
- cp += 0x10000;
+ cp = xs_surrogate_dec(cp, p2);
}
/* replace dangerous control codes with their visual representations */