StdLib: Rename method parameters (Strings)

This commit is contained in:
Ilya Gorbunov
2015-11-18 18:19:58 +03:00
parent bbe6a3c7ca
commit 7e7a55bbe4
5 changed files with 60 additions and 58 deletions
+2 -2
View File
@@ -26,8 +26,8 @@ public fun String.splitWithRegex(regex: String): Array<String> = noImpl
@library("splitString")
public fun String.splitWithRegex(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
@native public fun String.substring(startIndex : Int) : String = noImpl
@native public fun String.substring(startIndex : Int, endIndex : Int) : String = noImpl
@native public fun String.concat(str : String) : String = noImpl
+8 -8
View File
@@ -17,13 +17,13 @@ public fun String.startsWith(prefix: String, ignoreCase: Boolean = false): Boole
}
/**
* Returns `true` if a substring of this string starting at the specified offset [thisOffset] starts with the specified prefix.
* Returns `true` if a substring of this string starting at the specified offset [startIndex] starts with the specified prefix.
*/
public fun String.startsWith(prefix: String, thisOffset: Int, ignoreCase: Boolean = false): Boolean {
public fun String.startsWith(prefix: String, startIndex: Int, ignoreCase: Boolean = false): Boolean {
if (!ignoreCase)
return nativeStartsWith(prefix, thisOffset)
return nativeStartsWith(prefix, startIndex)
else
return regionMatches(thisOffset, prefix, 0, prefix.length(), ignoreCase)
return regionMatches(startIndex, prefix, 0, prefix.length(), ignoreCase)
}
/**
@@ -45,13 +45,13 @@ public inline fun String.matches(regex : String) : Boolean {
public fun CharSequence.isBlank(): Boolean = length() == 0 || (if (this is String) this else this.toString()).matches("^[\\s\\xA0]+$")
public fun String?.equals(anotherString: String?, ignoreCase: Boolean = false): Boolean =
public fun String?.equals(other: String?, ignoreCase: Boolean = false): Boolean =
if (this == null)
anotherString == null
other == null
else if (!ignoreCase)
this == anotherString
this == other
else
anotherString != null && this.toLowerCase() == anotherString.toLowerCase()
other != null && this.toLowerCase() == other.toLowerCase()
public fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean
+1 -1
View File
@@ -22,7 +22,7 @@ package kotlin
/**
* Concatenates this Char and a String.
*/
public operator fun Char.plus(string: String) : String = this.toString() + string
public operator fun Char.plus(other: String) : String = this.toString() + other
/**
* Returns `true` if this character is equal to the [other] character, optionally ignoring character case.
+33 -33
View File
@@ -287,9 +287,9 @@ public fun String.substring(range: IntRange): String = substring(range.start, ra
public fun CharSequence.subSequence(range: IntRange): CharSequence = subSequence(range.start, range.endInclusive + 1)
/**
* Returns a substring of chars from a range of this char sequence specified by [start] and [end] indices.
* Returns a substring of chars from a range of this char sequence specified by [startIndex] and [endIndex] indices.
*/
public fun CharSequence.substring(start: Int, end: Int = length): String = subSequence(start, end).toString()
public fun CharSequence.substring(startIndex: Int, endIndex: Int = length): String = subSequence(startIndex, endIndex).toString()
/**
* Returns a substring of chars from a [range] of this char sequence.
@@ -371,26 +371,26 @@ public fun String.substringAfterLast(delimiter: String, missingDelimiterValue: S
/**
* Returns a char sequence with content of this char sequence where its part at the given range
* is replaced with the [replacement] char sequence.
* @param firstIndex the index of the first character to be replaced.
* @param lastIndex the index of the first character after the replacement to keep in the string.
* @param startIndex the index of the first character to be replaced.
* @param endIndex the index of the first character after the replacement to keep in the string.
*/
public fun CharSequence.replaceRange(firstIndex: Int, lastIndex: Int, replacement: CharSequence): CharSequence {
if (lastIndex < firstIndex)
throw IndexOutOfBoundsException("Last index ($lastIndex) is less than first index ($firstIndex)")
public fun CharSequence.replaceRange(startIndex: Int, endIndex: Int, replacement: CharSequence): CharSequence {
if (endIndex < startIndex)
throw IndexOutOfBoundsException("End index ($endIndex) is less than start index ($startIndex)")
val sb = StringBuilder()
sb.append(this, 0, firstIndex)
sb.append(this, 0, startIndex)
sb.append(replacement)
sb.append(this, lastIndex, length)
sb.append(this, endIndex, length)
return sb
}
/**
* Replaces the part of the string at the given range with the [replacement] char sequence.
* @param firstIndex the index of the first character to be replaced.
* @param lastIndex the index of the first character after the replacement to keep in the string.
* @param startIndex the index of the first character to be replaced.
* @param endIndex the index of the first character after the replacement to keep in the string.
*/
public fun String.replaceRange(firstIndex: Int, lastIndex: Int, replacement: CharSequence): String
= (this as CharSequence).replaceRange(firstIndex, lastIndex, replacement).toString()
public fun String.replaceRange(startIndex: Int, endIndex: Int, replacement: CharSequence): String
= (this as CharSequence).replaceRange(startIndex, endIndex, replacement).toString()
/**
* Returns a char sequence with content of this char sequence where its part at the given [range]
@@ -412,33 +412,33 @@ public fun String.replaceRange(range: IntRange, replacement: CharSequence): Stri
/**
* Returns a char sequence with content of this char sequence where its part at the given range is removed.
*
* @param firstIndex the index of the first character to be removed.
* @param lastIndex the index of the first character after the removed part to keep in the string.
* @param startIndex the index of the first character to be removed.
* @param endIndex the index of the first character after the removed part to keep in the string.
*
* [lastIndex] is not included in the removed part.
* [endIndex] is not included in the removed part.
*/
public fun CharSequence.removeRange(firstIndex: Int, lastIndex: Int): CharSequence {
if (lastIndex < firstIndex)
throw IndexOutOfBoundsException("Last index ($lastIndex) is less than first index ($firstIndex)")
public fun CharSequence.removeRange(startIndex: Int, endIndex: Int): CharSequence {
if (endIndex < startIndex)
throw IndexOutOfBoundsException("End index ($endIndex) is less than start index ($startIndex)")
if (lastIndex == firstIndex)
if (endIndex == startIndex)
return this.subSequence(0, length)
val sb = StringBuilder(length - (lastIndex - firstIndex))
sb.append(this, 0, firstIndex)
sb.append(this, lastIndex, length)
val sb = StringBuilder(length - (endIndex - startIndex))
sb.append(this, 0, startIndex)
sb.append(this, endIndex, length)
return sb
}
/**
* Removes the part of a string at a given range.
* @param firstIndex the index of the first character to be removed.
* @param lastIndex the index of the first character after the removed part to keep in the string.
* @param startIndex the index of the first character to be removed.
* @param endIndex the index of the first character after the removed part to keep in the string.
*
* [lastIndex] is not included in the removed part.
* [endIndex] is not included in the removed part.
*/
public fun String.removeRange(firstIndex: Int, lastIndex: Int): String
= (this as CharSequence).removeRange(firstIndex, lastIndex).toString()
public fun String.removeRange(startIndex: Int, endIndex: Int): String
= (this as CharSequence).removeRange(startIndex, endIndex).toString()
/**
* Returns a char sequence with content of this char sequence where its part at the given [range] is removed.
@@ -681,13 +681,13 @@ public fun CharSequence.startsWith(prefix: CharSequence, ignoreCase: Boolean = f
}
/**
* Returns `true` if a substring of this char sequence starting at the specified offset [thisOffset] starts with the specified prefix.
* Returns `true` if a substring of this char sequence starting at the specified offset [startIndex] starts with the specified prefix.
*/
public fun CharSequence.startsWith(prefix: CharSequence, thisOffset: Int, ignoreCase: Boolean = false): Boolean {
public fun CharSequence.startsWith(prefix: CharSequence, startIndex: Int, ignoreCase: Boolean = false): Boolean {
if (!ignoreCase && this is String && prefix is String)
return this.startsWith(prefix, thisOffset)
return this.startsWith(prefix, startIndex)
else
return regionMatchesImpl(thisOffset, prefix, 0, prefix.length, ignoreCase)
return regionMatchesImpl(startIndex, prefix, 0, prefix.length, ignoreCase)
}
/**
@@ -1137,7 +1137,7 @@ public fun CharSequence.split(vararg delimiters: Char, ignoreCase: Boolean = fal
* @param limit Non-negative value specifying the maximum number of substrings to return.
* Zero by default means no limit is set.
*/
public fun CharSequence.split(pattern: Regex, limit: Int = 0): List<String> = pattern.split(this, limit)
public fun CharSequence.split(regex: Regex, limit: Int = 0): List<String> = regex.split(this, limit)
/**
* Splits this char sequence to a sequence of lines delimited by any of the following character sequences: CRLF, LF or CR.
+16 -14
View File
@@ -30,17 +30,17 @@ internal fun String.nativeLastIndexOf(ch: Char, fromIndex: Int): Int = (this as
internal fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int = (this as java.lang.String).lastIndexOf(str, fromIndex)
/**
* Returns `true` if this string is equal to [anotherString], optionally ignoring character case.
* Returns `true` if this string is equal to [other], optionally ignoring character case.
*
* @param ignoreCase `true` to ignore character case when comparing strings. By default `false`.
*/
public fun String?.equals(anotherString: String?, ignoreCase: Boolean = false): Boolean {
public fun String?.equals(other: String?, ignoreCase: Boolean = false): Boolean {
if (this === null)
return anotherString === null
return other === null
return if (!ignoreCase)
(this as java.lang.String).equals(anotherString)
(this as java.lang.String).equals(other)
else
(this as java.lang.String).equalsIgnoreCase(anotherString)
(this as java.lang.String).equalsIgnoreCase(other)
}
/**
@@ -120,12 +120,12 @@ public fun CharSequence.split(regex: Pattern, limit: Int = 0): List<String>
/**
* Returns a substring of this string starting with the specified index.
*/
public fun String.substring(beginIndex: Int): String = (this as java.lang.String).substring(beginIndex)
public fun String.substring(startIndex: Int): String = (this as java.lang.String).substring(startIndex)
/**
* Returns the substring of this string starting and ending at the specified indices.
*/
public fun String.substring(beginIndex: Int, endIndex: Int): String = (this as java.lang.String).substring(beginIndex, endIndex)
public fun String.substring(startIndex: Int, endIndex: Int): String = (this as java.lang.String).substring(startIndex, endIndex)
/**
* Returns `true` if this string starts with the specified prefix.
@@ -138,13 +138,13 @@ public fun String.startsWith(prefix: String, ignoreCase: Boolean = false): Boole
}
/**
* Returns `true` if a substring of this string starting at the specified offset [thisOffset] starts with the specified prefix.
* Returns `true` if a substring of this string starting at the specified offset [startIndex] starts with the specified prefix.
*/
public fun String.startsWith(prefix: String, thisOffset: Int, ignoreCase: Boolean = false): Boolean {
public fun String.startsWith(prefix: String, startIndex: Int, ignoreCase: Boolean = false): Boolean {
if (!ignoreCase)
return (this as java.lang.String).startsWith(prefix, thisOffset)
return (this as java.lang.String).startsWith(prefix, startIndex)
else
return regionMatches(thisOffset, prefix, 0, prefix.length, ignoreCase)
return regionMatches(startIndex, prefix, 0, prefix.length, ignoreCase)
}
/**
@@ -262,17 +262,18 @@ public fun String.compareTo(other: String, ignoreCase: Boolean = false): Int {
/**
* Returns a new string obtained by concatenating this string and the specified string.
*/
public fun String.concat(str: String): String = (this as java.lang.String).concat(str)
// TODO: Deprecated in favor of operator plus, when it would be as efficient as concat
public fun String.concat(other: String): String = (this as java.lang.String).concat(other)
/**
* Returns `true` if this string is equal to the contents of the specified CharSequence.
*/
public fun String.contentEquals(cs: CharSequence): Boolean = (this as java.lang.String).contentEquals(cs)
public fun String.contentEquals(charSequence: CharSequence): Boolean = (this as java.lang.String).contentEquals(charSequence)
/**
* Returns `true` if this string is equal to the contents of the specified StringBuffer.
*/
public fun String.contentEquals(sb: StringBuffer): Boolean = (this as java.lang.String).contentEquals(sb)
public fun String.contentEquals(stringBuilder: StringBuffer): Boolean = (this as java.lang.String).contentEquals(stringBuilder)
/**
* Copies the characters from a substring of this string into the specified character array.
@@ -388,6 +389,7 @@ public fun String.toCharList(): List<Char> = toCharArray().toList()
* @param start the start index (inclusive).
* @param end the end index (exclusive).
*/
@Deprecated("Use subSequence(start, end) instead.", ReplaceWith("subSequence(start, end)"))
public operator fun CharSequence.get(start: Int, end: Int): CharSequence = subSequence(start, end)
/**