readLine: extend buffer to decode surrogate pairs from utf-8 correctly
CharBuffer had capacity to hold 2 chars, which was not enough to append a surrogate pair when the buffer was not empty. The buffer was extended and the decoding algorithm rewritten to deal with a buffer of any length. #KT-28572 Fixed
This commit is contained in:
@@ -64,6 +64,16 @@ class ConsoleTest {
|
||||
testReadLine("first${linuxLineSeparator}second", listOf("first", "second"), charset = Charsets.UTF_32)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun readSurrogatePairs() {
|
||||
val c = "\uD83D\uDC4D" // thumb-up emoji
|
||||
testReadLine("$c$linuxLineSeparator", listOf(c))
|
||||
testReadLine("e $c$linuxLineSeparator", listOf("e $c"))
|
||||
testReadLine("$c$windowsLineSeparator", listOf(c))
|
||||
testReadLine("e $c$c", listOf("e $c$c"))
|
||||
testReadLine("e $c$linuxLineSeparator$c", listOf("e $c", c))
|
||||
}
|
||||
|
||||
private fun testReadLine(text: String, expected: List<String>, charset: Charset = Charsets.UTF_8) {
|
||||
val actual = readLines(text, charset)
|
||||
assertEquals(expected, actual)
|
||||
|
||||
Reference in New Issue
Block a user