Fix endsWith in JS always ignored character case, regardless of the ignoreCase parameter value.
startsWith, endsWith again use native implementation when possible.
This commit is contained in:
@@ -4,12 +4,21 @@ native public fun String.toUpperCase() : String = noImpl
|
||||
|
||||
native public fun String.toLowerCase() : String = noImpl
|
||||
|
||||
// TODO: make internal
|
||||
native("indexOf")
|
||||
public fun String.nativeIndexOf(str : String, fromIndex : Int) : Int = noImpl
|
||||
|
||||
// TODO: make internal
|
||||
native("lastIndexOf")
|
||||
public fun String.nativeLastIndexOf(str : String, fromIndex : Int) : Int = noImpl
|
||||
|
||||
// TODO: make internal
|
||||
native("startsWith")
|
||||
public fun String.nativeStartsWith(s: String, position: Int): Boolean = noImpl
|
||||
// TODO: make internal
|
||||
native("endsWith")
|
||||
public fun String.nativeEndsWith(s: String): Boolean = noImpl
|
||||
|
||||
library("splitString")
|
||||
public fun String.splitWithRegex(regex: String): Array<String> = noImpl
|
||||
|
||||
|
||||
@@ -1,25 +1,38 @@
|
||||
package kotlin.js
|
||||
|
||||
// TODO: make internal
|
||||
public inline fun String.nativeIndexOf(ch : Char, fromIndex : Int) : Int = nativeIndexOf(ch.toString(), fromIndex)
|
||||
public inline fun String.nativeLastIndexOf(ch : Char, fromIndex : Int) : Int = nativeLastIndexOf(ch.toString(), fromIndex)
|
||||
|
||||
/**
|
||||
* Returns `true` if this string starts with the specified prefix.
|
||||
*/
|
||||
public fun String.startsWith(prefix: String, ignoreCase: Boolean = false): Boolean =
|
||||
regionMatches(0, prefix, 0, prefix.length(), ignoreCase)
|
||||
public fun String.startsWith(prefix: String, ignoreCase: Boolean = false): Boolean {
|
||||
if (!ignoreCase)
|
||||
return nativeStartsWith(prefix, 0)
|
||||
else
|
||||
return regionMatches(0, prefix, 0, prefix.length(), ignoreCase)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if a substring of this string starting at the specified offset [thisOffset] starts with the specified prefix.
|
||||
*/
|
||||
public fun String.startsWith(prefix: String, thisOffset: Int, ignoreCase: Boolean = false): Boolean =
|
||||
regionMatches(thisOffset, prefix, 0, prefix.length(), ignoreCase)
|
||||
public fun String.startsWith(prefix: String, thisOffset: Int, ignoreCase: Boolean = false): Boolean {
|
||||
if (!ignoreCase)
|
||||
return nativeStartsWith(prefix, thisOffset)
|
||||
else
|
||||
return regionMatches(thisOffset, prefix, 0, prefix.length(), ignoreCase)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if this string ends with the specified suffix.
|
||||
*/
|
||||
public fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean =
|
||||
regionMatches(length() - suffix.length(), suffix, 0, suffix.length(), ignoreCase = true)
|
||||
public fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean {
|
||||
if (!ignoreCase)
|
||||
return nativeEndsWith(suffix)
|
||||
else
|
||||
return regionMatches(length() - suffix.length(), suffix, 0, suffix.length(), ignoreCase)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user