diff --git a/js/js.libraries/src/core/string.kt b/js/js.libraries/src/core/string.kt index ac110beeb00..90e9a06f2e0 100644 --- a/js/js.libraries/src/core/string.kt +++ b/js/js.libraries/src/core/string.kt @@ -26,14 +26,6 @@ deprecated("Use split(Regex) instead.") library("splitString") public fun String.splitWithRegex(regex: String, limit: Int): Array = noImpl -deprecated("Use split(Regex) instead.") -library("splitString") -public fun String.split(regex: String): Array = noImpl - -deprecated("Use split(Regex) instead.") -library("splitString") -public fun String.split(regex: String, limit: Int): Array = noImpl - native public fun String.substring(beginIndex : Int) : String = noImpl native public fun String.substring(beginIndex : Int, endIndex : Int) : String = noImpl diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index 21c6c7d2c87..5d3d7ba8e8f 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -532,26 +532,15 @@ public fun String.matches(regex: Regex): Boolean = regex.matches(this) /** * Returns `true` if this string starts with the specified character. */ -public fun String.startsWith(char: Char, ignoreCase: Boolean): Boolean = +public fun String.startsWith(char: Char, ignoreCase: Boolean = false): Boolean = this.length() > 0 && this[0].equals(char, ignoreCase) -/** - * Returns `true` if this string starts with the specified character. - */ -// TODO: temporary overload to keep binary compatibility, remove after fixing markdown parser -public fun String.startsWith(char: Char): Boolean = startsWith(char, ignoreCase = false) - /** * Returns `true` if this string ends with the specified character. */ -public fun String.endsWith(char: Char, ignoreCase: Boolean): Boolean = +public fun String.endsWith(char: Char, ignoreCase: Boolean = false): Boolean = this.length() > 0 && this[lastIndex].equals(char, ignoreCase) -/** - * Returns `true` if this string ends with the specified character. - */ -// TODO: temporary overload to keep binary compatibility, remove after fixing markdown parser -public fun String.endsWith(char: Char): Boolean = endsWith(char, ignoreCase = false) // common prefix and suffix @@ -920,7 +909,10 @@ public fun String.splitToSequence(vararg delimiters: String, ignoreCase: Boolean * the beginning to the end of this string, and matches at each position the first element in [delimiters] * that is equal to a delimiter in this instance at that position. */ -deprecated("Temporary name 'splitBy' shall be replaced soon with 'split'.") +public fun String.split(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): List = + splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit).toList() + +deprecated("Use split(delimiters) instead.") public fun String.splitBy(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): List = splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit).toList() diff --git a/libraries/stdlib/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/src/kotlin/text/StringsJVM.kt index e0feec8b208..6184514bba6 100644 --- a/libraries/stdlib/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/src/kotlin/text/StringsJVM.kt @@ -123,13 +123,6 @@ public fun String.format(locale: Locale, vararg args : Any?) : String = java.lan */ public fun String.split(regex: Pattern, limit: Int = 0): List = regex.split(this, limit).asList() -/** - * Splits this string around matches of the given regular expression. - */ -deprecated("Convert an argument to regex with toRegex or use splitBy instead.") -public fun String.split(regex: String): Array = split(regex.toRegex()).toTypedArray() - - /** * Returns a substring of this string starting with the specified index. */ diff --git a/libraries/stdlib/test/collections/CollectionTest.kt b/libraries/stdlib/test/collections/CollectionTest.kt index cbbbf17a814..14855edc77c 100644 --- a/libraries/stdlib/test/collections/CollectionTest.kt +++ b/libraries/stdlib/test/collections/CollectionTest.kt @@ -489,7 +489,7 @@ class CollectionTest { } test fun decomposeSplit() { - val (key, value) = "key = value".splitBy("=").map { it.trim() } + val (key, value) = "key = value".split("=").map { it.trim() } assertEquals(key, "key") assertEquals(value, "value") } diff --git a/libraries/stdlib/test/text/StringTest.kt b/libraries/stdlib/test/text/StringTest.kt index 9e9c9da078c..d55ac51c03d 100644 --- a/libraries/stdlib/test/text/StringTest.kt +++ b/libraries/stdlib/test/text/StringTest.kt @@ -353,18 +353,18 @@ class StringTest { test fun split() { - assertEquals(listOf(""), "".splitBy(";")) + assertEquals(listOf(""), "".split(";")) assertEquals(listOf("test"), "test".split(*charArray()), "empty list of delimiters, none matched -> entire string returned") - assertEquals(listOf("test"), "test".splitBy(*array()), "empty list of delimiters, none matched -> entire string returned") + assertEquals(listOf("test"), "test".split(*array()), "empty list of delimiters, none matched -> entire string returned") assertEquals(listOf("abc", "def", "123;456"), "abc;def,123;456".split(';', ',', limit = 3)) - assertEquals(listOf("abc", "def", "123", "456"), "abc
def
123
456".splitBy("
", ignoreCase = true)) + assertEquals(listOf("abc", "def", "123", "456"), "abc
def
123
456".split("
", ignoreCase = true)) - assertEquals(listOf("abc", "def", "123", "456"), "abc=-def==123=456".splitBy("==", "=-", "=")) + assertEquals(listOf("abc", "def", "123", "456"), "abc=-def==123=456".split("==", "=-", "=")) - assertEquals(listOf("", "a", "b", "c", ""), "abc".splitBy("")) - assertEquals(listOf("", "a", "b", "b", "a", ""), "abba".splitBy("", "a")) - assertEquals(listOf("", "", "b", "b", "", ""), "abba".splitBy("a", "")) + assertEquals(listOf("", "a", "b", "c", ""), "abc".split("")) + assertEquals(listOf("", "a", "b", "b", "a", ""), "abba".split("", "a")) + assertEquals(listOf("", "", "b", "b", "", ""), "abba".split("a", "")) } test fun splitToLines() {