Skip to content

Commit

Permalink
use writeU4Hex2
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jan 13, 2025
1 parent 4d45413 commit 2ef1c4d
Showing 1 changed file with 3 additions and 42 deletions.
45 changes: 3 additions & 42 deletions core/src/main/java/com/alibaba/fastjson2/JSONWriterUTF16.java
Original file line number Diff line number Diff line change
Expand Up @@ -796,25 +796,9 @@ protected final void writeStringEscape(byte[] str) {
case 5:
case 6:
case 7:
chars[off] = '\\';
chars[off + 1] = 'u';
chars[off + 2] = '0';
chars[off + 3] = '0';
chars[off + 4] = '0';
chars[off + 5] = (char) ('0' + (int) ch);
off += 6;
break;
case 11:
case 14:
case 15:
chars[off] = '\\';
chars[off + 1] = 'u';
chars[off + 2] = '0';
chars[off + 3] = '0';
chars[off + 4] = '0';
chars[off + 5] = (char) ('a' + (ch - 10));
off += 6;
break;
case 16:
case 17:
case 18:
Expand All @@ -825,52 +809,29 @@ protected final void writeStringEscape(byte[] str) {
case 23:
case 24:
case 25:
chars[off] = '\\';
chars[off + 1] = 'u';
chars[off + 2] = '0';
chars[off + 3] = '0';
chars[off + 4] = '1';
chars[off + 5] = (char) ('0' + (ch - 16));
off += 6;
break;
case 26:
case 27:
case 28:
case 29:
case 30:
case 31:
chars[off] = '\\';
chars[off + 1] = 'u';
chars[off + 2] = '0';
chars[off + 3] = '0';
chars[off + 4] = '1';
chars[off + 5] = (char) ('a' + (ch - 26));
writeU4Hex2(chars, off, ch);
off += 6;
break;
case '<':
case '>':
case '(':
case ')':
if (browserSecure) {
chars[off] = '\\';
chars[off + 1] = 'u';
chars[off + 2] = '0';
chars[off + 3] = '0';
chars[off + 4] = DIGITS[(ch >>> 4) & 15];
chars[off + 5] = DIGITS[ch & 15];
writeU4HexU(chars, off, ch);
off += 6;
} else {
chars[off++] = ch;
}
break;
default:
if (escapeNoneAscii && ch > 0x007F) {
chars[off] = '\\';
chars[off + 1] = 'u';
chars[off + 2] = '0';
chars[off + 3] = '0';
chars[off + 4] = DIGITS[(ch >>> 4) & 15];
chars[off + 5] = DIGITS[ch & 15];
writeU4HexU(chars, off, ch);
off += 6;
} else {
chars[off++] = ch;
Expand Down

0 comments on commit 2ef1c4d

Please sign in to comment.