2nd stage of split semantics change: remove deprecated String.split(String), rename splitBy back to split. Provide replacement for splitBy and splitWithRegex (JS).
This commit is contained in:
@@ -18,23 +18,14 @@ internal fun String.nativeStartsWith(s: String, position: Int): Boolean = noImpl
|
|||||||
native("endsWith")
|
native("endsWith")
|
||||||
internal fun String.nativeEndsWith(s: String): Boolean = noImpl
|
internal fun String.nativeEndsWith(s: String): Boolean = noImpl
|
||||||
|
|
||||||
deprecated("Use split(Regex) instead.")
|
deprecated("Use split(Regex) instead.", ReplaceWith("split(regex.toRegex()).toTypedArray()"))
|
||||||
library("splitString")
|
library("splitString")
|
||||||
public fun String.splitWithRegex(regex: String): Array<String> = noImpl
|
public fun String.splitWithRegex(regex: String): Array<String> = noImpl
|
||||||
|
|
||||||
deprecated("Use split(Regex) instead.")
|
deprecated("Use split(Regex) instead.", ReplaceWith("split(regex.toRegex(), limit = limit).toTypedArray()"))
|
||||||
library("splitString")
|
library("splitString")
|
||||||
public fun String.splitWithRegex(regex: String, limit: Int): Array<String> = noImpl
|
public fun String.splitWithRegex(regex: String, limit: Int): Array<String> = noImpl
|
||||||
|
|
||||||
deprecated("Use split(Regex) instead.")
|
|
||||||
library("splitString")
|
|
||||||
public fun String.split(regex: String): Array<String> = noImpl
|
|
||||||
|
|
||||||
deprecated("Use split(Regex) instead.")
|
|
||||||
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) : String = noImpl
|
||||||
native public fun String.substring(beginIndex : Int, endIndex : Int) : String = noImpl
|
native public fun String.substring(beginIndex : Int, endIndex : Int) : String = noImpl
|
||||||
|
|
||||||
|
|||||||
@@ -923,6 +923,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]
|
* 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.
|
* 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> =
|
||||||
|
splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit).toList()
|
||||||
|
|
||||||
|
deprecated("Use split(delimiters) instead.", ReplaceWith("split(*delimiters, ignoreCase = ignoreCase, limit = limit)"))
|
||||||
public fun String.splitBy(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): List<String> =
|
public fun String.splitBy(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): List<String> =
|
||||||
splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit).toList()
|
splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit).toList()
|
||||||
|
|
||||||
|
|||||||
@@ -128,17 +128,6 @@ public fun String.split(regex: Pattern, limit: Int = 0): List<String>
|
|||||||
require(limit >= 0, { "Limit must be non-negative, but was $limit" } )
|
require(limit >= 0, { "Limit must be non-negative, but was $limit" } )
|
||||||
return regex.split(this, if (limit == 0) -1 else limit).asList()
|
return regex.split(this, if (limit == 0) -1 else limit).asList()
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Splits this string around matches of the given regular expression.
|
|
||||||
*/
|
|
||||||
deprecated("Convert String argument to regex with toRegex or use splitBy instead for literal delimiters. Please note the change of return type.", ReplaceWith("split(regex.toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()"))
|
|
||||||
public fun String.split(regex: String): Array<String> = (this as java.lang.String).split(regex)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Splits this string into at most [limit] chunks around matches of the given regular expression.
|
|
||||||
*/
|
|
||||||
deprecated("Convert String argument to regex with toRegex or use splitBy instead for literal delimiters. Please note the change of return type and the restriction of limit to be non-negative.", ReplaceWith("split(regex.toRegex(), limit.coerceAtLeast(0)).toTypedArray()"))
|
|
||||||
public fun String.split(regex: String, limit: Int): Array<String> = (this as java.lang.String).split(regex, limit)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a substring of this string starting with the specified index.
|
* Returns a substring of this string starting with the specified index.
|
||||||
|
|||||||
@@ -353,18 +353,18 @@ class StringTest {
|
|||||||
|
|
||||||
|
|
||||||
test fun split() {
|
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".split(*charArray()), "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("test"), "test".split(*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;def,123;456".split(';', ',', limit = 3))
|
||||||
assertEquals(listOf("abc", "def", "123", "456"), "abc<BR>def<br>123<bR>456".splitBy("<BR>", ignoreCase = true))
|
assertEquals(listOf("abc", "def", "123", "456"), "abc<BR>def<br>123<bR>456".split("<BR>", 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", "c", ""), "abc".split(""))
|
||||||
assertEquals(listOf("", "a", "b", "b", "a", ""), "abba".splitBy("", "a"))
|
assertEquals(listOf("", "a", "b", "b", "a", ""), "abba".split("", "a"))
|
||||||
assertEquals(listOf("", "", "b", "b", "", ""), "abba".splitBy("a", ""))
|
assertEquals(listOf("", "", "b", "b", "", ""), "abba".split("a", ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
test fun splitToLines() {
|
test fun splitToLines() {
|
||||||
|
|||||||
Reference in New Issue
Block a user