Equivalize isLowerCase and isUpperCase behavior in all platforms #KT-46184

This commit is contained in:
Abduqodiri Qurbonzoda
2021-05-25 05:32:29 +03:00
parent 0b10f255d7
commit d934c97bf5
25 changed files with 386 additions and 75 deletions
@@ -51,17 +51,17 @@ internal fun Char.isLetterImpl(): Boolean {
}
/**
* Returns `true` if this character is a lower case letter.
* Returns `true` if this character is a lower case letter, or it has contributory property Other_Lowercase.
*/
internal fun Char.isLowerCaseImpl(): Boolean {
return getLetterType() == 1
return getLetterType() == 1 || code.isOtherLowercase()
}
/**
* Returns `true` if this character is an upper case letter.
* Returns `true` if this character is an upper case letter, or it has contributory property Other_Uppercase.
*/
internal fun Char.isUpperCaseImpl(): Boolean {
return getLetterType() == 2
return getLetterType() == 2 || code.isOtherUppercase()
}
/**
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.text
//
// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
private object OtherLowercase {
internal val otherLowerStart = intArrayOf(
0x00aa, 0x00ba, 0x02b0, 0x02c0, 0x02e0, 0x0345, 0x037a, 0x1d2c, 0x1d78, 0x1d9b, 0x2071, 0x207f, 0x2090, 0x2170, 0x24d0, 0x2c7c, 0xa69c, 0xa770, 0xa7f8, 0xab5c,
)
internal val otherLowerLength = intArrayOf(
1, 1, 9, 2, 5, 1, 1, 63, 1, 37, 1, 1, 13, 16, 26, 2, 2, 1, 2, 4,
)
}
internal fun Int.isOtherLowercase(): Boolean {
val index = binarySearchRange(OtherLowercase.otherLowerStart, this)
return index >= 0 && this < OtherLowercase.otherLowerStart[index] + OtherLowercase.otherLowerLength[index]
}
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.text
//
// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
internal fun Int.isOtherUppercase(): Boolean {
return this in 0x2160..0x216f
|| this in 0x24b6..0x24cf
}
+6 -4
View File
@@ -181,9 +181,10 @@ public actual fun Char.isDigit(): Boolean {
}
/**
* Returns `true` if this character is an upper case letter.
* Returns `true` if this character is upper case.
*
* A character is considered to be an upper case letter if its [category] is [CharCategory.UPPERCASE_LETTER].
* A character is considered to be an upper case character if its [category] is [CharCategory.UPPERCASE_LETTER],
* or it has contributory property Other_Uppercase as defined by the Unicode Standard.
*
* @sample samples.text.Chars.isUpperCase
*/
@@ -199,9 +200,10 @@ public actual fun Char.isUpperCase(): Boolean {
}
/**
* Returns `true` if this character is a lower case letter.
* Returns `true` if this character is lower case.
*
* A character is considered to be a lower case letter if its [category] is [CharCategory.LOWERCASE_LETTER].
* A character is considered to be a lower case character if its [category] is [CharCategory.LOWERCASE_LETTER],
* or it has contributory property Other_Lowercase as defined by the Unicode Standard.
*
* @sample samples.text.Chars.isLowerCase
*/