Rename split method to splitBy and revive old split implementation interpreting parameter as regex to provide the migration path.
This commit is contained in:
committed by
Ilya Gorbunov
parent
b10d869cd7
commit
b3165ac771
@@ -11,10 +11,19 @@ native("lastIndexOf")
|
||||
public fun String.nativeLastIndexOf(str : String, fromIndex : Int) : Int = noImpl
|
||||
|
||||
library("splitString")
|
||||
public fun String.splitByRegex(regex: String): Array<String> = noImpl
|
||||
public fun String.splitWithRegex(regex: String): Array<String> = noImpl
|
||||
|
||||
library("splitString")
|
||||
public fun String.splitByRegex(regex: String, limit: Int): Array<String> = noImpl
|
||||
public fun String.splitWithRegex(regex: String, limit: Int): Array<String> = noImpl
|
||||
|
||||
deprecated("Use splitWithRegex (temporary)")
|
||||
library("splitString")
|
||||
public fun String.split(regex: String): Array<String> = noImpl
|
||||
|
||||
deprecated("Use splitWithRegex (temporary)")
|
||||
library("splitString")
|
||||
public fun String.split(regex: String, limit: Int): Array<String> = noImpl
|
||||
|
||||
|
||||
native public fun String.substring(beginIndex : Int) : String = noImpl
|
||||
native public fun String.substring(beginIndex : Int, endIndex : Int) : String = noImpl
|
||||
|
||||
@@ -760,7 +760,8 @@ 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.
|
||||
*/
|
||||
public fun String.split(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): List<String> =
|
||||
deprecated("Temporary name 'splitBy' shall be replaced soon with 'split'.")
|
||||
public fun String.splitBy(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): List<String> =
|
||||
splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit).toList()
|
||||
|
||||
/**
|
||||
|
||||
@@ -95,6 +95,12 @@ public fun String.format(locale: Locale, vararg args : Any?) : String = java.lan
|
||||
*/
|
||||
public fun String.split(regex: Pattern, limit: Int = 0): List<String> = 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<String> = split(regex.toRegex()).copyToArray()
|
||||
|
||||
|
||||
/**
|
||||
* Returns a substring of this string starting with the specified index.
|
||||
|
||||
@@ -479,7 +479,7 @@ class CollectionTest {
|
||||
}
|
||||
|
||||
test fun decomposeSplit() {
|
||||
val (key, value) = "key = value".split("=").map { it.trim() }
|
||||
val (key, value) = "key = value".splitBy("=").map { it.trim() }
|
||||
assertEquals(key, "key")
|
||||
assertEquals(value, "value")
|
||||
}
|
||||
|
||||
@@ -292,14 +292,14 @@ class StringTest {
|
||||
|
||||
|
||||
test fun split() {
|
||||
assertEquals(listOf(""), "".split(";"))
|
||||
assertEquals(listOf(""), "".splitBy(";"))
|
||||
assertEquals(listOf("test"), "test".split(*charArray()), "empty list of delimiters, none matched -> entire string returned")
|
||||
assertEquals(listOf("test"), "test".split(*array<String>()), "empty list of delimiters, none matched -> entire string returned")
|
||||
assertEquals(listOf("test"), "test".splitBy(*array<String>()), "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<BR>def<br>123<bR>456".split("<BR>", ignoreCase = true))
|
||||
assertEquals(listOf("abc", "def", "123", "456"), "abc<BR>def<br>123<bR>456".splitBy("<BR>", ignoreCase = true))
|
||||
|
||||
assertEquals(listOf("abc", "def", "123", "456"), "abc=-def==123=456".split("==", "=-", "="))
|
||||
assertEquals(listOf("abc", "def", "123", "456"), "abc=-def==123=456".splitBy("==", "=-", "="))
|
||||
}
|
||||
|
||||
test fun splitToLines() {
|
||||
|
||||
Reference in New Issue
Block a user