Deprecate Char-to-Number conversions in stdlib (JVM and JS)
- Int.toChar was left non-deprecated because the replacement is not intrinsic yet. - Number.toChar was left non-deprecated because otherwise the deprecation propagates to the override, Int.toChar. KT-23451
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ internal class OneToManyUppercaseMappingsWriter(private val strategy: RangesWrit
|
||||
return null
|
||||
}
|
||||
|
||||
val code = this.toInt()
|
||||
val code = this.code
|
||||
val index = binarySearchRange(keys, code)
|
||||
if (keys[index] == code) {
|
||||
return values[index]
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ internal class LowercaseMappingsWriter(private val strategy: RangesWritingStrate
|
||||
|
||||
private fun lowercaseCharImpl(): String = """
|
||||
internal fun Char.lowercaseCharImpl(): Char {
|
||||
return toInt().lowercaseCodePoint().toChar()
|
||||
return code.lowercaseCodePoint().toChar()
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
+1
-1
@@ -24,7 +24,7 @@ internal class TitlecaseMappingsWriter : MappingsWriter {
|
||||
"""
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
internal fun Char.titlecaseCharImpl(): Char {
|
||||
val code = this.toInt()
|
||||
val code = this.code
|
||||
// Letters repeating <Lu, Lt, Ll> sequence and code of the Lt is a multiple of 3, e.g. <DŽ, Dž, dž>
|
||||
if (${rangeChecks(LuLtLlMappings, "code")}) {
|
||||
return (3 * ((code + 1) / 3)).toChar()
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ internal class UppercaseMappingsWriter(private val strategy: RangesWritingStrate
|
||||
|
||||
private fun uppercaseCharImpl(): String = """
|
||||
internal fun Char.uppercaseCharImpl(): Char {
|
||||
return toInt().uppercaseCodePoint().toChar()
|
||||
return code.uppercaseCodePoint().toChar()
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
+3
-3
@@ -94,7 +94,7 @@ internal class StringLowercaseGenerator(
|
||||
// Lu + Ll + Lt + Other_Lowercase + Other_Uppercase (PropList.txt of Unicode Character Database files)
|
||||
// Declared internal for testing
|
||||
internal fun Int.isCased(): Boolean {
|
||||
if (this <= Char.MAX_VALUE.toInt()) {
|
||||
if (this <= Char.MAX_VALUE.code) {
|
||||
when (toChar().getCategoryValue()) {
|
||||
CharCategory.UPPERCASE_LETTER.value,
|
||||
CharCategory.LOWERCASE_LETTER.value,
|
||||
@@ -110,7 +110,7 @@ internal class StringLowercaseGenerator(
|
||||
// Mn + Me + Cf + Lm + Sk + Word_Break=MidLetter + Word_Break=MidNumLet + Word_Break=Single_Quote (WordBreakProperty.txt of Unicode Character Database files)
|
||||
// Declared internal for testing
|
||||
internal fun Int.isCaseIgnorable(): Boolean {
|
||||
if (this <= Char.MAX_VALUE.toInt()) {
|
||||
if (this <= Char.MAX_VALUE.code) {
|
||||
when (toChar().getCategoryValue()) {
|
||||
CharCategory.NON_SPACING_MARK.value,
|
||||
CharCategory.ENCLOSING_MARK.value,
|
||||
@@ -133,7 +133,7 @@ internal class StringLowercaseGenerator(
|
||||
return Char.toCodePoint(high, low)
|
||||
}
|
||||
}
|
||||
return low.toInt()
|
||||
return low.code
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ internal class StringUppercaseGenerator(
|
||||
return Char.toCodePoint(high, low)
|
||||
}
|
||||
}
|
||||
return high.toInt()
|
||||
return high.code
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ class CharCategoryTest {
|
||||
properties = null
|
||||
}
|
||||
|
||||
val charCode = char.toInt().toString(radix = 16).padStart(length = 4, padChar = '0')
|
||||
val charCode = char.code.toString(radix = 16).padStart(length = 4, padChar = '0')
|
||||
val expectedCategoryCode = properties?.categoryCode ?: CharCategory.UNASSIGNED.code
|
||||
|
||||
fun <T> test(expected: T, actual: T, name: String) {
|
||||
|
||||
+3
-3
@@ -69,7 +69,7 @@ internal open class CategoryRangesWriter(protected val strategy: RangesWritingSt
|
||||
* Returns the Unicode general category of this character as an Int.
|
||||
*/
|
||||
internal fun Char.getCategoryValue(): Int {
|
||||
val ch = this.toInt()
|
||||
val ch = this.code
|
||||
|
||||
val index = ${indexOf("ch")}
|
||||
val start = ${startAt("index")}
|
||||
@@ -116,7 +116,7 @@ internal class VarLenBase64CategoryRangesWriter(strategy: RangesWritingStrategy)
|
||||
val toBase64 = "$TO_BASE64"
|
||||
val fromBase64 = IntArray(128)
|
||||
for (i in toBase64.indices) {
|
||||
fromBase64[toBase64[i].toInt()] = i
|
||||
fromBase64[toBase64[i].code] = i
|
||||
}
|
||||
|
||||
// rangeStartDiff.length = ${base64RangeLength.length}
|
||||
@@ -147,7 +147,7 @@ internal class VarLenBase64CategoryRangesWriter(strategy: RangesWritingStrategy)
|
||||
var int = 0
|
||||
var shift = 0
|
||||
for (char in base64) {
|
||||
val sixBit = fromBase64[char.toInt()]
|
||||
val sixBit = fromBase64[char.code]
|
||||
int = int or ((sixBit and 0x1f) shl shift)
|
||||
if (sixBit < 0x20) {
|
||||
result[index++] = int
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ internal class DigitRangesWriter(private val strategy: RangesWritingStrategy) :
|
||||
* Returns `true` if this character is a digit.
|
||||
*/
|
||||
internal fun Char.isDigitImpl(): Boolean {
|
||||
val ch = this.toInt()
|
||||
val ch = this.code
|
||||
val index = binarySearchRange($rangeStart, ch)
|
||||
val high = $rangeStart[index] + 9
|
||||
return ch <= high
|
||||
|
||||
+2
-2
@@ -81,7 +81,7 @@ internal open class LetterRangesWriter(protected val strategy: RangesWritingStra
|
||||
* - `0` otherwise.
|
||||
*/
|
||||
private fun Char.getLetterType(): Int {
|
||||
val ch = this.toInt()
|
||||
val ch = this.code
|
||||
val index = ${indexOf("ch")}
|
||||
|
||||
val rangeStart = ${startAt("index")}
|
||||
@@ -164,7 +164,7 @@ internal class VarLenBase64LetterRangesWriter(strategy: RangesWritingStrategy) :
|
||||
val toBase64 = "$TO_BASE64"
|
||||
val fromBase64 = IntArray(128)
|
||||
for (i in toBase64.indices) {
|
||||
fromBase64[toBase64[i].toInt()] = i
|
||||
fromBase64[toBase64[i].code] = i
|
||||
}
|
||||
|
||||
// rangeStartDiff.length = ${base64RangeStartDiff.length}
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ internal class WhitespaceRangesWriter : RangesWriter {
|
||||
* Returns `true` if this character is a whitespace.
|
||||
*/
|
||||
internal fun Char.isWhitespaceImpl(): Boolean {
|
||||
val ch = this.toInt()
|
||||
val ch = this.code
|
||||
return $checks
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@@ -988,7 +988,7 @@ object Elements : TemplateGroupBase() {
|
||||
specialFor(RangesOfPrimitives) {
|
||||
body {
|
||||
val expr = when (primitive) {
|
||||
PrimitiveType.Char -> "nextInt(first.toInt(), last.toInt() + 1).toChar()"
|
||||
PrimitiveType.Char -> "nextInt(first.code, last.code + 1).toChar()"
|
||||
else -> "next$primitive(this)"
|
||||
}
|
||||
"""
|
||||
@@ -1033,7 +1033,7 @@ object Elements : TemplateGroupBase() {
|
||||
specialFor(RangesOfPrimitives) {
|
||||
body {
|
||||
val expr = when (primitive) {
|
||||
PrimitiveType.Char -> "nextInt(first.toInt(), last.toInt() + 1).toChar()"
|
||||
PrimitiveType.Char -> "nextInt(first.code, last.code + 1).toChar()"
|
||||
else -> "next$primitive(this)"
|
||||
}
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user