2nd stage of split semantics change: remove deprecated String.split(String), rename splitBy back to split.

This commit is contained in:
Ilya Gorbunov
2015-04-03 22:07:07 +03:00
parent aa6bdb039b
commit b1255cf95b
5 changed files with 14 additions and 37 deletions
-8
View File
@@ -26,14 +26,6 @@ deprecated("Use split(Regex) instead.")
library("splitString")
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, endIndex : Int) : String = noImpl
+6 -14
View File
@@ -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<String> =
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<String> =
splitToSequence(*delimiters, ignoreCase = ignoreCase, limit = limit).toList()
@@ -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<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()).toTypedArray()
/**
* Returns a substring of this string starting with the specified index.
*/
@@ -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")
}
+7 -7
View File
@@ -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<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<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", "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() {