]> git.kaiwu.me - njs.git/commitdiff
Added macro for converting surrogate pair to code point.
authorAlexander Borisov <alexander.borisov@nginx.com>
Tue, 23 Apr 2019 15:10:37 +0000 (18:10 +0300)
committerAlexander Borisov <alexander.borisov@nginx.com>
Tue, 23 Apr 2019 15:10:37 +0000 (18:10 +0300)
njs/njs_json.c
njs/njs_parser_terminal.c
njs/njs_string.h

index e94d506a48de149059bee1520db90a0cee9b8fc6..203c236f67b086e46b6d4050cd2ca2070ad6d0e1 100644 (file)
@@ -820,7 +820,7 @@ njs_json_parse_string(njs_json_parse_ctx_t *ctx, njs_value_t *value,
                     return NULL;
                 }
 
-                utf = 0x10000 + ((utf - 0xd800) << 10) + (utf_low - 0xdc00);
+                utf = njs_string_surrogate_pair(utf, utf_low);
             }
 
             s = nxt_utf8_encode(s, utf);
index 77ade52995514a2014ae0ba1ed9a4c9b072f6152..72226c0ed436ba9d1eb5e4be44d2894faf2b9a41 100644 (file)
@@ -1048,10 +1048,8 @@ njs_parser_escape_string_create(njs_vm_t *vm, njs_parser_t *parser,
             src++;
         }
 
-        /* Surrogate pair. */
-
         if (cp_pair != 0) {
-            cp = 0x10000 + ((cp_pair - 0xd800) << 10) + (cp - 0xdc00);
+            cp = njs_string_surrogate_pair(cp_pair, cp);
             cp_pair = 0;
 
         } else if (cp >= 0xd800 && cp <= 0xdfff) {
@@ -1184,14 +1182,12 @@ njs_parser_escape_string_calc_length(njs_vm_t *vm, njs_parser_t *parser,
             }
         }
 
-        /* Surrogate pair. */
-
         if (cp_pair != 0) {
             if (nxt_slow_path(cp < 0xdc00 || cp > 0xdfff)) {
                 goto invalid_pair;
             }
 
-            cp = 0x10000 + ((cp_pair - 0xd800) << 10) + (cp - 0xdc00);
+            cp = njs_string_surrogate_pair(cp_pair, cp);
             cp_pair = 0;
 
         } else if (cp >= 0xd800 && cp <= 0xdfff) {
index f3c64621a096a73a60642785b2234e552c8d46dd..bf227d91a91b2be264030e2d2e75e2ccc48e5f71 100644 (file)
 /* The maximum signed int32_t. */
 #define NJS_STRING_MAX_LENGTH  0x7fffffff
 
+/* Converting surrogate pair to code point.  */
+#define njs_string_surrogate_pair(high, low)                                  \
+    (0x10000 + ((high - 0xd800) << 10) + (low - 0xdc00))
+
 /*
  * NJS_STRING_MAP_STRIDE should be power of two to use shift and binary
  * AND operations instead of division and remainder operations but no