@@ -309,28 +309,26 @@ static String valueToQuotedStringN(const char* value, unsigned length,
309
309
// Should add a flag to allow this compatibility mode and prevent this
310
310
// sequence from occurring.
311
311
default : {
312
- unsigned int codepoint =
313
- emitUTF8 ? static_cast <unsigned char >(*c) : utf8ToCodepoint (c, end);
314
- const unsigned int FIRST_NON_CONTROL_CODEPOINT = 0x20 ;
315
- const unsigned int LAST_NON_CONTROL_CODEPOINT = 0x7F ;
316
- const unsigned int FIRST_SURROGATE_PAIR_CODEPOINT = 0x10000 ;
317
-
318
- if ((codepoint < FIRST_NON_CONTROL_CODEPOINT) ||
319
- (!emitUTF8 && (codepoint >= LAST_NON_CONTROL_CODEPOINT))) {
320
- auto appendHexChar = [&result](unsigned ch) {
321
- result.append (" \\ u" ).append (toHex16Bit (ch));
322
- };
323
- if (codepoint < FIRST_SURROGATE_PAIR_CODEPOINT) {
312
+ const auto appendHexChar = [&result](unsigned ch) {
313
+ result.append (" \\ u" ).append (toHex16Bit (ch));
314
+ };
315
+
316
+ unsigned codepoint = static_cast <unsigned >(*c);
317
+ if (codepoint > 0x7F && !emitUTF8) {
318
+ codepoint = utf8ToCodepoint (c, end);
319
+ if (codepoint < 0x10000 ) {
324
320
// codepoint is in Basic Multilingual Plane
325
321
appendHexChar (codepoint);
326
322
} else {
327
323
// codepoint is not in Basic Multilingual Plane
328
- codepoint -= FIRST_SURROGATE_PAIR_CODEPOINT ;
324
+ codepoint -= 0x10000 ;
329
325
appendHexChar (0xD800 + (codepoint >> 10 ));
330
326
appendHexChar (0xDC00 + (codepoint & 0x3FF ));
331
327
}
328
+ } else if (codepoint < 0x20 ) {
329
+ appendHexChar (codepoint);
332
330
} else {
333
- result += *c ;
331
+ result += static_cast < char >(codepoint) ;
334
332
}
335
333
} break ;
336
334
}
0 commit comments