@@ -3549,27 +3549,28 @@ final class JsonReader private[jsoniter_scala](
3549
3549
if (buf(pos + 6 ) != '\\ ' ) escapeSequenceError(pos + 6 )
3550
3550
if (buf(pos + 7 ) != 'u' ) escapeSequenceError(pos + 7 )
3551
3551
val ch2 = readEscapedUnicode(pos + 8 , buf)
3552
- if (ch1 >= 0xDC00 || (ch2 & 0xFC00 ) != 0xDC00 ) decodeError(" illegal surrogate character pair" , pos + 11 )
3553
3552
charBuf(i + 1 ) = ch2
3553
+ if (ch1 >= 0xDC00 || (ch2 & 0xFC00 ) != 0xDC00 ) decodeError(" illegal surrogate character pair" , pos + 11 )
3554
3554
parseEncodedString(i + 2 , lim, charBuf, pos + 12 )
3555
3555
} else parseEncodedString(i, lim, charBuf, loadMoreOrError(pos))
3556
3556
} else parseEncodedString(i, lim, charBuf, loadMoreOrError(pos))
3557
3557
} else parseEncodedString(i, lim, charBuf, loadMoreOrError(pos))
3558
3558
} else if ((b1 & 0xE0 ) == 0xC0 ) { // 110bbbbb 10aaaaaa (UTF-8 bytes) -> 00000bbbbbaaaaaa (UTF-16 char)
3559
3559
if (remaining > 1 ) {
3560
3560
val b2 = buf(pos + 1 )
3561
- if ((b1 & 0x1E ) == 0 || (b2 & 0xC0 ) != 0x80 ) malformedBytesError(b1, b2, pos)
3562
- charBuf(i) = (b1 << 6 ^ b2 ^ 0xF80 ).toChar // 0xF80 == 0xC0.toByte << 6 ^ 0x80.toByte
3561
+ val ch = (b1 << 6 ^ b2 ^ 0xF80 ).toChar // 0xF80 == 0xC0.toByte << 6 ^ 0x80.toByte
3562
+ charBuf(i) = ch
3563
+ if ((b2 & 0xC0 ) != 0x80 || ch < 0x80 ) malformedBytesError(b1, b2, pos)
3563
3564
parseEncodedString(i + 1 , lim, charBuf, pos + 2 )
3564
3565
} else parseEncodedString(i, lim, charBuf, loadMoreOrError(pos))
3565
3566
} else if ((b1 & 0xF0 ) == 0xE0 ) { // 1110cccc 10bbbbbb 10aaaaaa (UTF-8 bytes) -> ccccbbbbbbaaaaaa (UTF-16 char)
3566
3567
if (remaining > 2 ) {
3567
3568
val b2 = buf(pos + 1 )
3568
3569
val b3 = buf(pos + 2 )
3569
- val ch = (b1 << 12 ^ b2 << 6 ^ b3 ^ 0xFFFE1F80 ).toChar // 0xFFFE1F80 == 0xE0.toByte << 12 ^ 0x80.toByte << 6 ^ 0x80.toByte
3570
- if ((b1 == - 32 && (b2 & 0xE0 ) == 0x80 ) || (b2 & 0xC0 ) != 0x80 || (b3 & 0xC0 ) != 0x80 ||
3571
- (ch & 0xF800 ) == 0xD800 ) malformedBytesError(b1, b2, b3, pos)
3570
+ val ch = (b1 << 12 ^ b2 << 6 ^ b3 ^ 0x1F80 ).toChar // 0x1F80 == (0x80.toByte << 6 ^ 0x80.toByte).toChar
3572
3571
charBuf(i) = ch
3572
+ if ((b2 & 0xC0 ) != 0x80 || (b3 & 0xC0 ) != 0x80 || ch < 0x800 ||
3573
+ (ch & 0xF800 ) == 0xD800 ) malformedBytesError(b1, b2, b3, pos)
3573
3574
parseEncodedString(i + 1 , lim, charBuf, pos + 3 )
3574
3575
} else parseEncodedString(i, lim, charBuf, loadMoreOrError(pos))
3575
3576
} else if ((b1 & 0xF8 ) == 0xF0 ) { // 11110ddd 10ddcccc 10bbbbbb 10aaaaaa (UTF-8 bytes) -> 110110uuuuccccbb 110111bbbbaaaaaa (UTF-16 chars), where uuuu = ddddd - 1
@@ -3578,10 +3579,11 @@ final class JsonReader private[jsoniter_scala](
3578
3579
val b3 = buf(pos + 2 )
3579
3580
val b4 = buf(pos + 3 )
3580
3581
val cp = b1 << 18 ^ b2 << 12 ^ b3 << 6 ^ b4 ^ 0x381F80 // 0x381F80 == 0xF0.toByte << 18 ^ 0x80.toByte << 12 ^ 0x80.toByte << 6 ^ 0x80.toByte
3581
- if ((b2 & 0xC0 ) != 0x80 || (b3 & 0xC0 ) != 0x80 || (b4 & 0xC0 ) != 0x80 ||
3582
- cp < 0x10000 || cp > 0x10FFFF ) malformedBytesError(b1, b2, b3, b4, pos)
3583
- charBuf(i) = ((cp >>> 10 ) + 0xD7C0 ).toChar // 0xD7C0 == 0xD800 - (0x10000 >>> 10)
3582
+ val ch1 = ((cp >>> 10 ) + 0xD7C0 ).toChar // 0xD7C0 == 0xD800 - (0x10000 >>> 10)
3583
+ charBuf(i) = ch1
3584
3584
charBuf(i + 1 ) = ((cp & 0x3FF ) + 0xDC00 ).toChar
3585
+ if ((b2 & 0xC0 ) != 0x80 || (b3 & 0xC0 ) != 0x80 || (b4 & 0xC0 ) != 0x80 ||
3586
+ (ch1 & 0xF800 ) != 0xD800 ) malformedBytesError(b1, b2, b3, b4, pos)
3585
3587
parseEncodedString(i + 2 , lim, charBuf, pos + 4 )
3586
3588
} else parseEncodedString(i, lim, charBuf, loadMoreOrError(pos))
3587
3589
} else malformedBytesError(b1, pos)
@@ -3599,49 +3601,51 @@ final class JsonReader private[jsoniter_scala](
3599
3601
else if (b1 != '\\ ' ) { // 0aaaaaaa (UTF-8 byte) -> 000000000aaaaaaa (UTF-16 char)
3600
3602
if (b1 < ' ' ) unescapedControlCharacterError(pos)
3601
3603
head = pos + 1
3602
- b1.toChar
3604
+ return b1.toChar
3603
3605
} else if (remaining > 1 ) {
3604
3606
val b2 = buf(pos + 1 )
3605
3607
if (b2 != 'u' ) {
3606
3608
head = pos + 2
3607
3609
(b2 : @ switch) match {
3608
- case 'b' => '\b '
3609
- case 'f' => '\f '
3610
- case 'n' => '\n '
3611
- case 'r' => '\r '
3612
- case 't' => '\t '
3613
- case '"' => '"'
3614
- case '/' => '/'
3615
- case '\\ ' => '\\ '
3610
+ case 'b' => return '\b '
3611
+ case 'f' => return '\f '
3612
+ case 'n' => return '\n '
3613
+ case 'r' => return '\r '
3614
+ case 't' => return '\t '
3615
+ case '"' => return '"'
3616
+ case '/' => return '/'
3617
+ case '\\ ' => return '\\ '
3616
3618
case _ => escapeSequenceError(pos + 1 )
3617
3619
}
3618
3620
} else if (remaining > 5 ) {
3619
3621
val ch = readEscapedUnicode(pos + 2 , buf)
3620
- if ((ch & 0xF800 ) == 0xD800 ) surrogateCharacterError(pos + 5 )
3621
3622
head = pos + 6
3622
- ch
3623
- } else parseChar(loadMoreOrError(pos))
3624
- } else parseChar(loadMoreOrError(pos))
3623
+ if ((ch & 0xF800 ) == 0xD800 ) surrogateCharacterError(pos + 5 )
3624
+ return ch
3625
+ }
3626
+ }
3625
3627
} else if ((b1 & 0xE0 ) == 0xC0 ) { // 110bbbbb 10aaaaaa (UTF-8 bytes) -> 00000bbbbbaaaaaa (UTF-16 char)
3626
3628
if (remaining > 1 ) {
3627
3629
val b2 = buf(pos + 1 )
3628
- if (( b1 & 0x1E ) == 0 || ( b2 & 0xC0 ) != 0x80 ) malformedBytesError(b1, b2, pos)
3630
+ val ch = ( b1 << 6 ^ b2 ^ 0xF80 ).toChar // 0xF80 == 0xC0.toByte << 6 ^ 0x80.toByte
3629
3631
head = pos + 2
3630
- (b1 << 6 ^ b2 ^ 0xF80 ).toChar // 0xF80 == 0xC0.toByte << 6 ^ 0x80.toByte
3631
- } else parseChar(loadMoreOrError(pos))
3632
+ if ((b2 & 0xC0 ) != 0x80 || ch < 0x80 ) malformedBytesError(b1, b2, pos)
3633
+ return ch
3634
+ }
3632
3635
} else if ((b1 & 0xF0 ) == 0xE0 ) { // 1110cccc 10bbbbbb 10aaaaaa (UTF-8 bytes) -> ccccbbbbbbaaaaaa (UTF-16 char)
3633
3636
if (remaining > 2 ) {
3634
3637
val b2 = buf(pos + 1 )
3635
3638
val b3 = buf(pos + 2 )
3636
- val ch = (b1 << 12 ^ b2 << 6 ^ b3 ^ 0xFFFE1F80 ).toChar // 0xFFFE1F80 == 0xE0.toByte << 12 ^ 0x80.toByte << 6 ^ 0x80.toByte
3637
- if ((b1 == - 32 && (b2 & 0xE0 ) == 0x80 ) || (b2 & 0xC0 ) != 0x80 || (b3 & 0xC0 ) != 0x80 ||
3638
- (ch & 0xF800 ) == 0xD800 ) malformedBytesError(b1, b2, b3, pos)
3639
+ val ch = (b1 << 12 ^ b2 << 6 ^ b3 ^ 0x1F80 ).toChar // 0x1F80 == (0x80.toByte << 6 ^ 0x80.toByte).toChar
3639
3640
head = pos + 3
3640
- ch
3641
- } else parseChar(loadMoreOrError(pos))
3641
+ if ((b2 & 0xC0 ) != 0x80 || (b3 & 0xC0 ) != 0x80 || ch < 0x800 ||
3642
+ (ch & 0xF800 ) == 0xD800 ) malformedBytesError(b1, b2, b3, pos)
3643
+ return ch
3644
+ }
3642
3645
} else if ((b1 & 0xF8 ) == 0xF0 ) surrogateCharacterError(pos + 3 )
3643
3646
else malformedBytesError(b1, pos)
3644
- } else parseChar(loadMoreOrError(pos))
3647
+ }
3648
+ parseChar(loadMoreOrError(pos))
3645
3649
}
3646
3650
3647
3651
private [this ] def readEscapedUnicode (pos : Int , buf : Array [Byte ]): Char = {
0 commit comments