Revert using regex Pattern in String.replace

Use String.indexOf(..., ignoreCase) instead in all branches to preserve
compatibility with behavior before 1.4.20 that used String.split which
essentially relied on that String.indexOf

#KT-43745 Fixed
This commit is contained in:
Ilya Gorbunov
2020-12-04 11:49:05 +03:00
parent 5167d69b7c
commit 149bcc2d22
2 changed files with 17 additions and 11 deletions
+16
View File
@@ -896,6 +896,22 @@ class StringTest {
assertEquals("-a-b-b-A-b-", input.replace("", "-"))
assertEquals("-a-b-b-A-b-", input.replace("", "-", ignoreCase = true))
fun testIgnoreCase(chars: String) {
for ((i, c) in chars.withIndex()) {
val message = "Char: $c (${c.toInt()})"
val expectOneReplaced = chars.replaceRange(i..i, "_")
val expectAllReplaced = "_".repeat(chars.length)
assertEquals(expectOneReplaced, chars.replace(c, '_'), message)
assertEquals(expectAllReplaced, chars.replace(c, '_', ignoreCase = true), "$message, ignoreCase")
assertEquals(expectOneReplaced, chars.replace(c.toString(), "_"), "$message, as string")
assertEquals(expectAllReplaced, chars.replace(c.toString(), "_", ignoreCase = true), "$message, as string, ignoreCase")
}
}
testIgnoreCase("üÜ")
testIgnoreCase("öÖ")
testIgnoreCase("äÄ")
}
@Test fun replaceFirst() {