@@ -660,10 +660,6 @@ public void writeUTF8String(byte[] text, int offset, int len) throws IOException
660
660
_outputBuffer [_outputTail ++] = _quoteChar ;
661
661
}
662
662
663
- private boolean isSurrogatePair (char ch ) {
664
- return (ch & 0xD800 ) == 0xD800 ;
665
- }
666
-
667
663
/*
668
664
/**********************************************************
669
665
/* Output method implementations, unprocessed ("raw")
@@ -1494,8 +1490,6 @@ private final void _writeStringSegment2(final char[] cbuf, int offset, final int
1494
1490
final byte [] outputBuffer = _outputBuffer ;
1495
1491
final int [] escCodes = _outputEscapes ;
1496
1492
1497
- boolean combineSurrogates = Feature .COMBINE_UNICODE_SURROGATES_IN_UTF8 .enabledIn (_features );
1498
-
1499
1493
while (offset < end ) {
1500
1494
int ch = cbuf [offset ++];
1501
1495
if (ch <= 0x7F ) {
@@ -1517,14 +1511,17 @@ private final void _writeStringSegment2(final char[] cbuf, int offset, final int
1517
1511
outputBuffer [outputPtr ++] = (byte ) (0xc0 | (ch >> 6 ));
1518
1512
outputBuffer [outputPtr ++] = (byte ) (0x80 | (ch & 0x3f ));
1519
1513
} else {
1520
- // multibyte character
1521
- if (combineSurrogates && isSurrogatePair ((char ) ch ) && offset < end ) {
1522
- char highSurrogate = (char ) ch ;
1523
- char lowSurrogate = cbuf [offset ++];
1524
- outputPtr = _outputSurrogatePair (highSurrogate , lowSurrogate , outputPtr );
1525
- } else {
1526
- outputPtr = _outputMultiByteChar (ch , outputPtr );
1514
+ // 3- or 4-byte character
1515
+ if (_isSurrogateChar ((char ) ch )) {
1516
+ final boolean combineSurrogates = Feature .COMBINE_UNICODE_SURROGATES_IN_UTF8 .enabledIn (_features );
1517
+ if (combineSurrogates && offset < end ) {
1518
+ char highSurrogate = (char ) ch ;
1519
+ char lowSurrogate = cbuf [offset ++];
1520
+ outputPtr = _outputSurrogatePair (highSurrogate , lowSurrogate , outputPtr );
1521
+ continue ;
1522
+ }
1527
1523
}
1524
+ outputPtr = _outputMultiByteChar (ch , outputPtr );
1528
1525
}
1529
1526
}
1530
1527
_outputTail = outputPtr ;
@@ -1541,8 +1538,6 @@ private final void _writeStringSegment2(final String text, int offset, final int
1541
1538
final byte [] outputBuffer = _outputBuffer ;
1542
1539
final int [] escCodes = _outputEscapes ;
1543
1540
1544
- boolean combineSurrogates = Feature .COMBINE_UNICODE_SURROGATES_IN_UTF8 .enabledIn (_features );
1545
-
1546
1541
while (offset < end ) {
1547
1542
int ch = text .charAt (offset ++);
1548
1543
if (ch <= 0x7F ) {
@@ -1564,14 +1559,17 @@ private final void _writeStringSegment2(final String text, int offset, final int
1564
1559
outputBuffer [outputPtr ++] = (byte ) (0xc0 | (ch >> 6 ));
1565
1560
outputBuffer [outputPtr ++] = (byte ) (0x80 | (ch & 0x3f ));
1566
1561
} else {
1567
- // multibyte character
1568
- if (combineSurrogates && isSurrogatePair ((char ) ch ) && offset < end ) {
1569
- char highSurrogate = (char ) ch ;
1570
- char lowSurrogate = text .charAt (offset ++);
1571
- outputPtr = _outputSurrogatePair (highSurrogate , lowSurrogate , outputPtr );
1572
- } else {
1573
- outputPtr = _outputMultiByteChar (ch , outputPtr );
1562
+ // 3- or 4-byte character
1563
+ if (_isSurrogateChar ((char ) ch )) {
1564
+ final boolean combineSurrogates = Feature .COMBINE_UNICODE_SURROGATES_IN_UTF8 .enabledIn (_features );
1565
+ if (combineSurrogates && offset < end ) {
1566
+ char highSurrogate = (char ) ch ;
1567
+ char lowSurrogate = text .charAt (offset ++);
1568
+ outputPtr = _outputSurrogatePair (highSurrogate , lowSurrogate , outputPtr );
1569
+ continue ;
1570
+ }
1574
1571
}
1572
+ outputPtr = _outputMultiByteChar (ch , outputPtr );
1575
1573
}
1576
1574
}
1577
1575
_outputTail = outputPtr ;
@@ -2244,5 +2242,10 @@ protected final void _flushBuffer() throws IOException
2244
2242
private byte [] getHexBytes () {
2245
2243
return _cfgWriteHexUppercase ? HEX_BYTES_UPPER : HEX_BYTES_LOWER ;
2246
2244
}
2245
+
2246
+ // @since 2.18
2247
+ private boolean _isSurrogateChar (char ch ) {
2248
+ return (ch & 0xD800 ) == 0xD800 ;
2249
+ }
2247
2250
}
2248
2251
0 commit comments