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
@@ -68,17 +68,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
//
@SharedImmutable
private val otherLowerStart = intArrayOf(
0x00aa, 0x00ba, 0x02b0, 0x02c0, 0x02e0, 0x0345, 0x037a, 0x1d2c, 0x1d78, 0x1d9b, 0x2071, 0x207f, 0x2090, 0x2170, 0x24d0, 0x2c7c, 0xa69c, 0xa770, 0xa7f8, 0xab5c,
)
@SharedImmutable
private 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(otherLowerStart, this)
return index >= 0 && this < otherLowerStart[index] + otherLowerLength[index]
}
@@ -0,0 +1,19 @@
/*
* 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
|| this in 0x1f130..0x1f149
|| this in 0x1f150..0x1f169
|| this in 0x1f170..0x1f189
}
@@ -12,17 +12,13 @@ package kotlin.text
@SharedImmutable
private val casedStart = intArrayOf(
0x00aa, 0x00ba, 0x02b0, 0x02c0, 0x02e0, 0x0345, 0x037a, 0x1d2c, 0x1d78, 0x1d9b, 0x2071, 0x207f, 0x2090, 0x2160, 0x2170, 0x24b6, 0x24d0, 0x2c7c, 0xa69c, 0xa770,
0xa7f8, 0xab5c, 0x10400, 0x104b0, 0x104d8, 0x10c80, 0x10cc0, 0x118a0, 0x16e40, 0x1d400, 0x1d456, 0x1d49e, 0x1d4a2, 0x1d4a5, 0x1d4a9, 0x1d4ae, 0x1d4bb, 0x1d4bd, 0x1d4c5, 0x1d507,
0x1d50d, 0x1d516, 0x1d51e, 0x1d53b, 0x1d540, 0x1d546, 0x1d54a, 0x1d552, 0x1d6a8, 0x1d6c2, 0x1d6dc, 0x1d6fc, 0x1d716, 0x1d736, 0x1d750, 0x1d770, 0x1d78a, 0x1d7aa, 0x1d7c4, 0x1e900,
0x1f130, 0x1f150, 0x1f170,
0x10400, 0x104b0, 0x104d8, 0x10c80, 0x10cc0, 0x118a0, 0x16e40, 0x1d400, 0x1d456, 0x1d49e, 0x1d4a2, 0x1d4a5, 0x1d4a9, 0x1d4ae, 0x1d4bb, 0x1d4bd, 0x1d4c5, 0x1d507, 0x1d50d, 0x1d516,
0x1d51e, 0x1d53b, 0x1d540, 0x1d546, 0x1d54a, 0x1d552, 0x1d6a8, 0x1d6c2, 0x1d6dc, 0x1d6fc, 0x1d716, 0x1d736, 0x1d750, 0x1d770, 0x1d78a, 0x1d7aa, 0x1d7c4, 0x1e900,
)
@SharedImmutable
private val casedEnd = intArrayOf(
0x00aa, 0x00ba, 0x02b8, 0x02c1, 0x02e4, 0x0345, 0x037a, 0x1d6a, 0x1d78, 0x1dbf, 0x2071, 0x207f, 0x209c, 0x216f, 0x217f, 0x24cf, 0x24e9, 0x2c7d, 0xa69d, 0xa770,
0xa7f9, 0xab5f, 0x1044f, 0x104d3, 0x104fb, 0x10cb2, 0x10cf2, 0x118df, 0x16e7f, 0x1d454, 0x1d49c, 0x1d49f, 0x1d4a2, 0x1d4a6, 0x1d4ac, 0x1d4b9, 0x1d4bb, 0x1d4c3, 0x1d505, 0x1d50a,
0x1d514, 0x1d51c, 0x1d539, 0x1d53e, 0x1d544, 0x1d546, 0x1d550, 0x1d6a5, 0x1d6c0, 0x1d6da, 0x1d6fa, 0x1d714, 0x1d734, 0x1d74e, 0x1d76e, 0x1d788, 0x1d7a8, 0x1d7c2, 0x1d7cb, 0x1e943,
0x1f149, 0x1f169, 0x1f189,
0x1044f, 0x104d3, 0x104fb, 0x10cb2, 0x10cf2, 0x118df, 0x16e7f, 0x1d454, 0x1d49c, 0x1d49f, 0x1d4a2, 0x1d4a6, 0x1d4ac, 0x1d4b9, 0x1d4bb, 0x1d4c3, 0x1d505, 0x1d50a, 0x1d514, 0x1d51c,
0x1d539, 0x1d53e, 0x1d544, 0x1d546, 0x1d550, 0x1d6a5, 0x1d6c0, 0x1d6da, 0x1d6fa, 0x1d714, 0x1d734, 0x1d74e, 0x1d76e, 0x1d788, 0x1d7a8, 0x1d7c2, 0x1d7cb, 0x1e943,
)
// Lu + Ll + Lt + Other_Lowercase + Other_Uppercase (PropList.txt of Unicode Character Database files)
@@ -35,6 +31,9 @@ internal fun Int.isCased(): Boolean {
CharCategory.TITLECASE_LETTER.value -> return true
}
}
if (isOtherUppercase() || isOtherLowercase()) {
return true
}
val index = binarySearchRange(casedStart, this)
return index >= 0 && this <= casedEnd[index]
}
@@ -101,9 +101,10 @@ external public actual fun Char.isISOControl(): Boolean
public actual fun Char.isWhitespace(): Boolean = isWhitespaceImpl()
/**
* 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
*/
@@ -118,9 +119,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
*/