Align JS String.equals/compareTo(ignoreCase) behavior with JVM #KT-48999

This commit is contained in:
Abduqodiri Qurbonzoda
2021-09-30 15:35:50 +00:00
committed by Space
parent b5f74ef9a6
commit f8bcba0b76
8 changed files with 77 additions and 30 deletions
@@ -35,6 +35,9 @@ internal actual external fun String.nativeLastIndexOf(str: String, fromIndex: In
/**
* Returns `true` if this string is equal to [other], optionally ignoring character case.
*
* Two strings are considered to be equal if they have the same length and the same character at the same index.
* If [ignoreCase] is true, the result of `Char.uppercaseChar().lowercaseChar()` on each character is compared.
*
* @param ignoreCase `true` to ignore character case when comparing strings. By default `false`.
*/
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
@@ -475,6 +478,11 @@ internal fun compareToIgnoreCase(thiz: String, other: String): Int {
1
}
/**
* Compares two strings lexicographically, optionally ignoring case differences.
*
* If [ignoreCase] is true, the result of `Char.uppercaseChar().lowercaseChar()` on each character is compared.
*/
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun String.compareTo(other: String, ignoreCase: Boolean = false): Int {
return if (!ignoreCase) this.compareTo(other)