Make proposed split replacement equivalent in behavior with additional dropLastWhile call.

#KT-7887
This commit is contained in:
Ilya Gorbunov
2015-06-01 16:19:13 +03:00
parent 9b17220baa
commit 9f85fa9720
2 changed files with 4 additions and 1 deletions
@@ -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.
*/
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)
/**
@@ -65,6 +65,9 @@ class StringJVMTest {
assertEquals(listOf("ab", "cd", "def", ""), s.split(isDigit))
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 {
s.split(isDigit, -1)
}