Skip to content

Commit 8a1417e

Browse files
committed
Code-review fixes 2
1 parent d268648 commit 8a1417e

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

Diff for: src/lib_json/json_writer.cpp

+12-14
Original file line numberDiff line numberDiff line change
@@ -309,28 +309,26 @@ static String valueToQuotedStringN(const char* value, unsigned length,
309309
// Should add a flag to allow this compatibility mode and prevent this
310310
// sequence from occurring.
311311
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) {
324320
// codepoint is in Basic Multilingual Plane
325321
appendHexChar(codepoint);
326322
} else {
327323
// codepoint is not in Basic Multilingual Plane
328-
codepoint -= FIRST_SURROGATE_PAIR_CODEPOINT;
324+
codepoint -= 0x10000;
329325
appendHexChar(0xD800 + (codepoint >> 10));
330326
appendHexChar(0xDC00 + (codepoint & 0x3FF));
331327
}
328+
} else if (codepoint < 0x20) {
329+
appendHexChar(codepoint);
332330
} else {
333-
result += *c;
331+
result += static_cast<char>(codepoint);
334332
}
335333
} break;
336334
}

0 commit comments

Comments
 (0)