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:
Ilya Gorbunov
2021-04-06 15:36:44 +03:00
parent b976cd812a
commit b64b96eee6
59 changed files with 273 additions and 169 deletions
@@ -183,7 +183,7 @@ internal object LineReader {
bytes[nBytes++] = readByte.toByte()
}
// With "directEOL" encoding bytes are batched before being decoded all at once
if (readByte == '\n'.toInt() || nBytes == BUFFER_SIZE || !directEOL) {
if (readByte == '\n'.code || nBytes == BUFFER_SIZE || !directEOL) {
// Decode the bytes that were read
byteBuf.limit(nBytes) // byteBuf position is always zero
charBuf.position(nChars) // charBuf limit is always BUFFER_SIZE
@@ -254,7 +254,7 @@ internal object LineReader {
// try decoding ASCII line separator to see if this charset (like UTF-8) encodes it directly
byteBuf.clear()
charBuf.clear()
byteBuf.put('\n'.toByte())
byteBuf.put('\n'.code.toByte())
byteBuf.flip()
decoder.decode(byteBuf, charBuf, false)
directEOL = charBuf.position() == 1 && charBuf.get(0) == '\n'
@@ -288,7 +288,7 @@ public actual inline fun Char.isLowSurrogate(): Boolean = Character.isLowSurroga
internal actual fun digitOf(char: Char, radix: Int): Int = Character.digit(char.toInt(), radix)
internal actual fun digitOf(char: Char, radix: Int): Int = Character.digit(char.code, radix)
/**
* Checks whether the given [radix] is valid radix for string to number and number to string conversion.
@@ -21,7 +21,7 @@ import java.util.regex.Pattern
* Returns the index within this string of the first occurrence of the specified character, starting from the specified offset.
*/
@kotlin.internal.InlineOnly
internal actual inline fun String.nativeIndexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).indexOf(ch.toInt(), fromIndex)
internal actual inline fun String.nativeIndexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).indexOf(ch.code, fromIndex)
/**
* Returns the index within this string of the first occurrence of the specified substring, starting from the specified offset.
@@ -33,7 +33,7 @@ internal actual inline fun String.nativeIndexOf(str: String, fromIndex: Int): In
* Returns the index within this string of the last occurrence of the specified character.
*/
@kotlin.internal.InlineOnly
internal actual inline fun String.nativeLastIndexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).lastIndexOf(ch.toInt(), fromIndex)
internal actual inline fun String.nativeLastIndexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).lastIndexOf(ch.code, fromIndex)
/**
* Returns the index within this string of the last occurrence of the specified character, starting from the specified offset.