Make proposed split replacement equivalent in behavior with additional dropLastWhile call.
#KT-7887
This commit is contained in:
@@ -131,7 +131,7 @@ public fun String.split(regex: Pattern, limit: Int = 0): List<String>
|
|||||||
/**
|
/**
|
||||||
* Splits this string around matches of the given regular expression.
|
* 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()).toTypedArray()"))
|
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)
|
public fun String.split(regex: String): Array<String> = (this as java.lang.String).split(regex)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ class StringJVMTest {
|
|||||||
assertEquals(listOf("ab", "cd", "def", ""), s.split(isDigit))
|
assertEquals(listOf("ab", "cd", "def", ""), s.split(isDigit))
|
||||||
assertEquals(listOf("ab", "cd", "def3"), s.split(isDigit, 3))
|
assertEquals(listOf("ab", "cd", "def3"), s.split(isDigit, 3))
|
||||||
|
|
||||||
|
// deprecation replacement equivalence
|
||||||
|
assertEquals("\\d".toPattern().split(s).toList(), s.split("\\d".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray().toList())
|
||||||
|
|
||||||
fails {
|
fails {
|
||||||
s.split(isDigit, -1)
|
s.split(isDigit, -1)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user