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:
@@ -1021,6 +1021,8 @@ public final class Byte : kotlin.Number, kotlin.Comparable<kotlin.Byte> {
|
||||
|
||||
public open override fun toByte(): kotlin.Byte
|
||||
|
||||
@kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public open override fun toChar(): kotlin.Char
|
||||
|
||||
public open override fun toDouble(): kotlin.Double
|
||||
@@ -1079,18 +1081,30 @@ public final class Char : kotlin.Comparable<kotlin.Char> {
|
||||
|
||||
public final operator fun rangeTo(other: kotlin.Char): kotlin.ranges.CharRange
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toByte()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toByte(): kotlin.Byte
|
||||
|
||||
public final fun toChar(): kotlin.Char
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toDouble()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toDouble(): kotlin.Double
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toFloat()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toFloat(): kotlin.Float
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toInt(): kotlin.Int
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toLong()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toLong(): kotlin.Long
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toShort()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toShort(): kotlin.Short
|
||||
|
||||
public companion object of Char {
|
||||
@@ -1315,6 +1329,8 @@ public final class Double : kotlin.Number, kotlin.Comparable<kotlin.Double> {
|
||||
@kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3")
|
||||
public open override fun toByte(): kotlin.Byte
|
||||
|
||||
@kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public open override fun toChar(): kotlin.Char
|
||||
|
||||
public open override fun toDouble(): kotlin.Double
|
||||
@@ -1552,6 +1568,8 @@ public final class Float : kotlin.Number, kotlin.Comparable<kotlin.Float> {
|
||||
@kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3")
|
||||
public open override fun toByte(): kotlin.Byte
|
||||
|
||||
@kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public open override fun toChar(): kotlin.Char
|
||||
|
||||
public open override fun toDouble(): kotlin.Double
|
||||
@@ -1933,6 +1951,8 @@ public final class Long : kotlin.Number, kotlin.Comparable<kotlin.Long> {
|
||||
|
||||
public open override fun toByte(): kotlin.Byte
|
||||
|
||||
@kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public open override fun toChar(): kotlin.Char
|
||||
|
||||
public open override fun toDouble(): kotlin.Double
|
||||
@@ -2254,6 +2274,8 @@ public final class Short : kotlin.Number, kotlin.Comparable<kotlin.Short> {
|
||||
|
||||
public open override fun toByte(): kotlin.Byte
|
||||
|
||||
@kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {}))
|
||||
/*∆*/ @kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public open override fun toChar(): kotlin.Char
|
||||
|
||||
public open override fun toDouble(): kotlin.Double
|
||||
|
||||
@@ -987,6 +987,8 @@ public final class Byte : kotlin.Number, kotlin.Comparable<kotlin.Byte> {
|
||||
|
||||
public open override fun toByte(): kotlin.Byte
|
||||
|
||||
@kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public open override fun toChar(): kotlin.Char
|
||||
|
||||
public open override fun toDouble(): kotlin.Double
|
||||
@@ -1055,18 +1057,30 @@ public final class Char : kotlin.Comparable<kotlin.Char> {
|
||||
|
||||
public final operator fun rangeTo(other: kotlin.Char): kotlin.ranges.CharRange
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toByte()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toByte(): kotlin.Byte
|
||||
|
||||
public final fun toChar(): kotlin.Char
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toDouble()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toDouble(): kotlin.Double
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toFloat()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toFloat(): kotlin.Float
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toInt(): kotlin.Int
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toLong()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toLong(): kotlin.Long
|
||||
|
||||
@kotlin.Deprecated(message = "Conversion of Char to Number is deprecated. Use Char.code property instead.", replaceWith = kotlin.ReplaceWith(expression = "this.code.toShort()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public final fun toShort(): kotlin.Short
|
||||
|
||||
/*∆*/ @kotlin.js.JsName(name = "toString")
|
||||
@@ -1290,6 +1304,8 @@ public final class Double : kotlin.Number, kotlin.Comparable<kotlin.Double> {
|
||||
@kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3")
|
||||
public open override fun toByte(): kotlin.Byte
|
||||
|
||||
@kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public open override fun toChar(): kotlin.Char
|
||||
|
||||
public open override fun toDouble(): kotlin.Double
|
||||
@@ -1531,6 +1547,8 @@ public final class Float : kotlin.Number, kotlin.Comparable<kotlin.Float> {
|
||||
@kotlin.DeprecatedSinceKotlin(errorSince = "1.5", warningSince = "1.3")
|
||||
public open override fun toByte(): kotlin.Byte
|
||||
|
||||
@kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public open override fun toChar(): kotlin.Char
|
||||
|
||||
public open override fun toDouble(): kotlin.Double
|
||||
@@ -1921,6 +1939,8 @@ public final class Long : kotlin.Number, kotlin.Comparable<kotlin.Long> {
|
||||
|
||||
public open override fun toByte(): kotlin.Byte
|
||||
|
||||
@kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {}))
|
||||
@kotlin.DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public open override fun toChar(): kotlin.Char
|
||||
|
||||
public open override fun toDouble(): kotlin.Double
|
||||
@@ -2248,6 +2268,7 @@ public final class Short : kotlin.Number, kotlin.Comparable<kotlin.Short> {
|
||||
|
||||
public open override fun toByte(): kotlin.Byte
|
||||
|
||||
@kotlin.Deprecated(message = "Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", replaceWith = kotlin.ReplaceWith(expression = "this.toInt().toChar()", imports = {}))
|
||||
public open override fun toChar(): kotlin.Char
|
||||
|
||||
public open override fun toDouble(): kotlin.Double
|
||||
|
||||
@@ -84,7 +84,7 @@ public fun LongRange.random(random: Random): Long {
|
||||
@SinceKotlin("1.3")
|
||||
public fun CharRange.random(random: Random): Char {
|
||||
try {
|
||||
return random.nextInt(first.toInt(), last.toInt() + 1).toChar()
|
||||
return random.nextInt(first.code, last.code + 1).toChar()
|
||||
} catch(e: IllegalArgumentException) {
|
||||
throw NoSuchElementException(e.message)
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public fun LongRange.randomOrNull(random: Random): Long? {
|
||||
public fun CharRange.randomOrNull(random: Random): Char? {
|
||||
if (isEmpty())
|
||||
return null
|
||||
return random.nextInt(first.toInt(), last.toInt() + 1).toChar()
|
||||
return random.nextInt(first.code, last.code + 1).toChar()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,18 +41,30 @@ constructor(code: UShort) : Comparable<Char> {
|
||||
public operator fun rangeTo(other: Char): CharRange = CharRange(this, other)
|
||||
|
||||
/** Returns the value of this character as a `Byte`. */
|
||||
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toByte()"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public fun toByte(): Byte = value.toByte()
|
||||
/** Returns the value of this character as a `Char`. */
|
||||
public fun toChar(): Char = this
|
||||
/** Returns the value of this character as a `Short`. */
|
||||
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toShort()"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public fun toShort(): Short = value.toShort()
|
||||
/** Returns the value of this character as a `Int`. */
|
||||
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public fun toInt(): Int = value
|
||||
/** Returns the value of this character as a `Long`. */
|
||||
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toLong()"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public fun toLong(): Long = value.toLong()
|
||||
/** Returns the value of this character as a `Float`. */
|
||||
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toFloat()"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public fun toFloat(): Float = value.toFloat()
|
||||
/** Returns the value of this character as a `Double`. */
|
||||
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toDouble()"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public fun toDouble(): Double = value.toDouble()
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
|
||||
@@ -202,6 +202,8 @@ public class Byte private constructor() : Number(), Comparable<Byte> {
|
||||
* The least significant 8 bits of the resulting `Char` code are the same as the bits of this `Byte` value,
|
||||
* whereas the most significant 8 bits are filled with the sign bit of this value.
|
||||
*/
|
||||
@Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public override fun toChar(): Char
|
||||
/**
|
||||
* Converts this [Byte] value to [Short].
|
||||
@@ -447,6 +449,7 @@ public class Short private constructor() : Number(), Comparable<Short> {
|
||||
* The resulting `Char` code is equal to this value reinterpreted as an unsigned number,
|
||||
* i.e. it has the same binary representation as this `Short`.
|
||||
*/
|
||||
@Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()"))
|
||||
public override fun toChar(): Char
|
||||
/** Returns this value. */
|
||||
public override fun toShort(): Short
|
||||
@@ -966,6 +969,8 @@ public class Float private constructor() : Number(), Comparable<Float> {
|
||||
*
|
||||
* The resulting `Char` value is equal to `this.toInt().toChar()`.
|
||||
*/
|
||||
@Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public override fun toChar(): Char
|
||||
/**
|
||||
* Converts this [Float] value to [Short].
|
||||
@@ -1210,6 +1215,8 @@ public class Double private constructor() : Number(), Comparable<Double> {
|
||||
*
|
||||
* The resulting `Char` value is equal to `this.toInt().toChar()`.
|
||||
*/
|
||||
@Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public override fun toChar(): Char
|
||||
/**
|
||||
* Converts this [Double] value to [Short].
|
||||
|
||||
@@ -262,6 +262,8 @@ public class Long internal constructor(
|
||||
public fun inv(): Long = Long(low.inv(), high.inv())
|
||||
|
||||
public override fun toByte(): Byte = low.toByte()
|
||||
@Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.5")
|
||||
public override fun toChar(): Char = low.toChar()
|
||||
public override fun toShort(): Short = low.toShort()
|
||||
public override fun toInt(): Int = low
|
||||
|
||||
@@ -19,7 +19,7 @@ private object Category {
|
||||
val toBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
val fromBase64 = IntArray(128)
|
||||
for (i in toBase64.indices) {
|
||||
fromBase64[toBase64[i].toInt()] = i
|
||||
fromBase64[toBase64[i].code] = i
|
||||
}
|
||||
|
||||
// rangeStartDiff.length = 1482
|
||||
@@ -54,7 +54,7 @@ private fun categoryValueFrom(code: Int, ch: Int): Int {
|
||||
* 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 = binarySearchRange(Category.decodedRangeStart, ch)
|
||||
val start = Category.decodedRangeStart[index]
|
||||
@@ -70,7 +70,7 @@ internal fun decodeVarLenBase64(base64: String, fromBase64: IntArray, resultLeng
|
||||
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
|
||||
|
||||
@@ -40,7 +40,7 @@ internal fun binarySearchRange(array: IntArray, needle: Int): Int {
|
||||
* Returns `true` if this character is a digit.
|
||||
*/
|
||||
internal fun Char.isDigitImpl(): Boolean {
|
||||
val ch = this.toInt()
|
||||
val ch = this.code
|
||||
val index = binarySearchRange(Digit.rangeStart, ch)
|
||||
val high = Digit.rangeStart[index] + 9
|
||||
return ch <= high
|
||||
|
||||
@@ -20,7 +20,7 @@ private object Letter {
|
||||
val toBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
val fromBase64 = IntArray(128)
|
||||
for (i in toBase64.indices) {
|
||||
fromBase64[toBase64[i].toInt()] = i
|
||||
fromBase64[toBase64[i].code] = i
|
||||
}
|
||||
|
||||
// rangeStartDiff.length = 356
|
||||
@@ -72,7 +72,7 @@ internal fun Char.isUpperCaseImpl(): Boolean {
|
||||
* - `0` otherwise.
|
||||
*/
|
||||
private fun Char.getLetterType(): Int {
|
||||
val ch = this.toInt()
|
||||
val ch = this.code
|
||||
val index = binarySearchRange(Letter.decodedRangeStart, ch)
|
||||
|
||||
val rangeStart = Letter.decodedRangeStart[index]
|
||||
|
||||
@@ -13,7 +13,7 @@ package kotlin.text
|
||||
// 4 ranges totally
|
||||
@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 (code in 0x01c4..0x01cc || code in 0x01f1..0x01f3) {
|
||||
return (3 * ((code + 1) / 3)).toChar()
|
||||
|
||||
@@ -15,7 +15,7 @@ package kotlin.text
|
||||
* Returns `true` if this character is a whitespace.
|
||||
*/
|
||||
internal fun Char.isWhitespaceImpl(): Boolean {
|
||||
val ch = this.toInt()
|
||||
val ch = this.code
|
||||
return ch in 0x0009..0x000d
|
||||
|| ch in 0x001c..0x0020
|
||||
|| ch == 0x00a0
|
||||
|
||||
@@ -19,7 +19,7 @@ private object Category {
|
||||
val toBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
val fromBase64 = IntArray(128)
|
||||
for (i in toBase64.indices) {
|
||||
fromBase64[toBase64[i].toInt()] = i
|
||||
fromBase64[toBase64[i].code] = i
|
||||
}
|
||||
|
||||
// rangeStartDiff.length = 1482
|
||||
@@ -54,7 +54,7 @@ private fun categoryValueFrom(code: Int, ch: Int): Int {
|
||||
* 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 = binarySearchRange(Category.decodedRangeStart, ch)
|
||||
val start = Category.decodedRangeStart[index]
|
||||
@@ -70,7 +70,7 @@ internal fun decodeVarLenBase64(base64: String, fromBase64: IntArray, resultLeng
|
||||
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
|
||||
|
||||
@@ -40,7 +40,7 @@ internal fun binarySearchRange(array: IntArray, needle: Int): Int {
|
||||
* Returns `true` if this character is a digit.
|
||||
*/
|
||||
internal fun Char.isDigitImpl(): Boolean {
|
||||
val ch = this.toInt()
|
||||
val ch = this.code
|
||||
val index = binarySearchRange(Digit.rangeStart, ch)
|
||||
val high = Digit.rangeStart[index] + 9
|
||||
return ch <= high
|
||||
|
||||
@@ -20,7 +20,7 @@ private object Letter {
|
||||
val toBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
val fromBase64 = IntArray(128)
|
||||
for (i in toBase64.indices) {
|
||||
fromBase64[toBase64[i].toInt()] = i
|
||||
fromBase64[toBase64[i].code] = i
|
||||
}
|
||||
|
||||
// rangeStartDiff.length = 356
|
||||
@@ -72,7 +72,7 @@ internal fun Char.isUpperCaseImpl(): Boolean {
|
||||
* - `0` otherwise.
|
||||
*/
|
||||
private fun Char.getLetterType(): Int {
|
||||
val ch = this.toInt()
|
||||
val ch = this.code
|
||||
val index = binarySearchRange(Letter.decodedRangeStart, ch)
|
||||
|
||||
val rangeStart = Letter.decodedRangeStart[index]
|
||||
|
||||
@@ -13,7 +13,7 @@ package kotlin.text
|
||||
// 4 ranges totally
|
||||
@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 (code in 0x01c4..0x01cc || code in 0x01f1..0x01f3) {
|
||||
return (3 * ((code + 1) / 3)).toChar()
|
||||
|
||||
@@ -15,7 +15,7 @@ package kotlin.text
|
||||
* Returns `true` if this character is a whitespace.
|
||||
*/
|
||||
internal fun Char.isWhitespaceImpl(): Boolean {
|
||||
val ch = this.toInt()
|
||||
val ch = this.code
|
||||
return ch in 0x0009..0x000d
|
||||
|| ch in 0x001c..0x0020
|
||||
|| ch == 0x00a0
|
||||
|
||||
@@ -23,7 +23,7 @@ private fun codePointFromSurrogate(string: String, high: Int, index: Int, endInd
|
||||
if (high !in 0xD800..0xDBFF || index >= endIndex) {
|
||||
return malformed(0, index, throwOnMalformed)
|
||||
}
|
||||
val low = string[index].toInt()
|
||||
val low = string[index].code
|
||||
if (low !in 0xDC00..0xDFFF) {
|
||||
return malformed(0, index, throwOnMalformed)
|
||||
}
|
||||
@@ -169,7 +169,7 @@ internal fun encodeUtf8(string: String, startIndex: Int, endIndex: Int, throwOnM
|
||||
var charIndex = startIndex
|
||||
|
||||
while (charIndex < endIndex) {
|
||||
val code = string[charIndex++].toInt()
|
||||
val code = string[charIndex++].code
|
||||
when {
|
||||
code < 0x80 ->
|
||||
bytes[byteIndex++] = code.toByte()
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -84,7 +84,7 @@ class ReadWriteTest {
|
||||
//file.replaceText("Hello\nWorld")
|
||||
file.forEachBlock { arr: ByteArray, size: Int ->
|
||||
assertTrue(size >= 11 && size <= 12, size.toString())
|
||||
assertTrue(arr.contains('W'.toByte()))
|
||||
assertTrue(arr.contains('W'.code.toByte()))
|
||||
}
|
||||
val list = ArrayList<String>()
|
||||
file.forEachLine(Charsets.UTF_8, {
|
||||
|
||||
@@ -68,7 +68,7 @@ class Arrays {
|
||||
fun associateArrayOfPrimitives() {
|
||||
val charCodes = intArrayOf(72, 69, 76, 76, 79)
|
||||
|
||||
val byCharCode = charCodes.associate { it to it.toChar() }
|
||||
val byCharCode = charCodes.associate { it to Char(it) }
|
||||
|
||||
// 76=L only occurs once because only the last pair with the same key gets added
|
||||
assertPrints(byCharCode, "{72=H, 69=E, 76=L, 79=O}")
|
||||
@@ -79,7 +79,7 @@ class Arrays {
|
||||
fun associateArrayOfPrimitivesBy() {
|
||||
val charCodes = intArrayOf(72, 69, 76, 76, 79)
|
||||
|
||||
val byChar = charCodes.associateBy { it.toChar() }
|
||||
val byChar = charCodes.associateBy { Char(it) }
|
||||
|
||||
// L=76 only occurs once because only the last pair with the same key gets added
|
||||
assertPrints(byChar, "{H=72, E=69, L=76, O=79}")
|
||||
@@ -89,7 +89,7 @@ class Arrays {
|
||||
fun associateArrayOfPrimitivesByWithValueTransform() {
|
||||
val charCodes = intArrayOf(65, 65, 66, 67, 68, 69)
|
||||
|
||||
val byUpperCase = charCodes.associateBy({ it.toChar() }, { (it + 32).toChar() })
|
||||
val byUpperCase = charCodes.associateBy({ Char(it) }, { Char(it + 32) })
|
||||
|
||||
// A=a only occurs once because only the last pair with the same key gets added
|
||||
assertPrints(byUpperCase, "{A=a, B=b, C=c, D=d, E=e}")
|
||||
@@ -101,7 +101,7 @@ class Arrays {
|
||||
val byChar = mutableMapOf<Char, Int>()
|
||||
|
||||
assertTrue(byChar.isEmpty())
|
||||
charCodes.associateByTo(byChar) { it.toChar() }
|
||||
charCodes.associateByTo(byChar) { Char(it) }
|
||||
|
||||
assertTrue(byChar.isNotEmpty())
|
||||
// L=76 only occurs once because only the last pair with the same key gets added
|
||||
@@ -113,7 +113,7 @@ class Arrays {
|
||||
val charCodes = intArrayOf(65, 65, 66, 67, 68, 69)
|
||||
|
||||
val byUpperCase = mutableMapOf<Char, Char>()
|
||||
charCodes.associateByTo(byUpperCase, { it.toChar() }, { (it + 32).toChar() } )
|
||||
charCodes.associateByTo(byUpperCase, { Char(it) }, { Char(it + 32) })
|
||||
|
||||
// A=a only occurs once because only the last pair with the same key gets added
|
||||
assertPrints(byUpperCase, "{A=a, B=b, C=c, D=d, E=e}")
|
||||
@@ -124,7 +124,7 @@ class Arrays {
|
||||
val charCodes = intArrayOf(72, 69, 76, 76, 79)
|
||||
|
||||
val byChar = mutableMapOf<Int, Char>()
|
||||
charCodes.associateTo(byChar) { it to it.toChar() }
|
||||
charCodes.associateTo(byChar) { it to Char(it) }
|
||||
|
||||
// 76=L only occurs once because only the last pair with the same key gets added
|
||||
assertPrints(byChar, "{72=H, 69=E, 76=L, 79=O}")
|
||||
|
||||
@@ -35,7 +35,7 @@ class Chars {
|
||||
val chars = listOf('\u0000', '\u000E', '\u0009', '1', 'a')
|
||||
val (isoControls, notIsoControls) = chars.partition { it.isISOControl() }
|
||||
// some ISO-control char codes
|
||||
assertPrints(isoControls.map(Char::toInt), "[0, 14, 9]")
|
||||
assertPrints(isoControls.map(Char::code), "[0, 14, 9]")
|
||||
// non-ISO-control chars
|
||||
assertPrints(notIsoControls, "[1, a]")
|
||||
}
|
||||
@@ -61,7 +61,7 @@ class Chars {
|
||||
val chars = listOf(' ', '\t', '\n', '1', 'a', '\u00A0')
|
||||
val (whitespaces, notWhitespaces) = chars.partition { it.isWhitespace() }
|
||||
// whitespace char codes
|
||||
assertPrints(whitespaces.map(Char::toInt), "[32, 9, 10, 160]")
|
||||
assertPrints(whitespaces.map(Char::code), "[32, 9, 10, 160]")
|
||||
// non-whitespace chars
|
||||
assertPrints(notWhitespaces, "[1, a]")
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ class Strings {
|
||||
fun associate() {
|
||||
val string = "bonne journée"
|
||||
// associate each character with its code
|
||||
val result = string.associate { char -> char to char.toInt() }
|
||||
val result = string.associate { char -> char to char.code }
|
||||
// notice each letter occurs only once
|
||||
assertPrints(result, "{b=98, o=111, n=110, e=101, =32, j=106, u=117, r=114, é=233}")
|
||||
}
|
||||
@@ -135,7 +135,7 @@ class Strings {
|
||||
fun associateBy() {
|
||||
val string = "bonne journée"
|
||||
// associate each character by its code
|
||||
val result = string.associateBy { char -> char.toInt() }
|
||||
val result = string.associateBy { char -> char.code }
|
||||
// notice each char code occurs only once
|
||||
assertPrints(result, "{98=b, 111=o, 110=n, 101=e, 32= , 106=j, 117=u, 114=r, 233=é}")
|
||||
}
|
||||
@@ -144,7 +144,7 @@ class Strings {
|
||||
fun associateByWithValueTransform() {
|
||||
val string = "bonne journée"
|
||||
// associate each character by the code of its upper case equivalent and transform the character to upper case
|
||||
val result = string.associateBy({ char -> char.toUpperCase().toInt() }, { char -> char.toUpperCase() })
|
||||
val result = string.associateBy({ char -> char.uppercaseChar().code }, { char -> char.uppercaseChar() })
|
||||
// notice each char code occurs only once
|
||||
assertPrints(result, "{66=B, 79=O, 78=N, 69=E, 32= , 74=J, 85=U, 82=R, 201=É}")
|
||||
}
|
||||
@@ -154,7 +154,7 @@ class Strings {
|
||||
val string = "bonne journée"
|
||||
// associate each character by its code
|
||||
val result = mutableMapOf<Int, Char>()
|
||||
string.associateByTo(result) { char -> char.toInt() }
|
||||
string.associateByTo(result) { char -> char.code }
|
||||
// notice each char code occurs only once
|
||||
assertPrints(result, "{98=b, 111=o, 110=n, 101=e, 32= , 106=j, 117=u, 114=r, 233=é}")
|
||||
}
|
||||
@@ -164,7 +164,7 @@ class Strings {
|
||||
val string = "bonne journée"
|
||||
// associate each character by the code of its upper case equivalent and transform the character to upper case
|
||||
val result = mutableMapOf<Int, Char>()
|
||||
string.associateByTo(result, { char -> char.toUpperCase().toInt() }, { char -> char.toUpperCase() })
|
||||
string.associateByTo(result, { char -> char.uppercaseChar().code }, { char -> char.uppercaseChar() })
|
||||
// notice each char code occurs only once
|
||||
assertPrints(result, "{66=B, 79=O, 78=N, 69=E, 32= , 74=J, 85=U, 82=R, 201=É}")
|
||||
}
|
||||
@@ -174,7 +174,7 @@ class Strings {
|
||||
val string = "bonne journée"
|
||||
// associate each character with its code
|
||||
val result = mutableMapOf<Char, Int>()
|
||||
string.associateTo(result) { char -> char to char.toInt() }
|
||||
string.associateTo(result) { char -> char to char.code }
|
||||
// notice each letter occurs only once
|
||||
assertPrints(result, "{b=98, o=111, n=110, e=101, =32, j=106, u=117, r=114, é=233}")
|
||||
}
|
||||
@@ -183,7 +183,7 @@ class Strings {
|
||||
fun associateWith() {
|
||||
val string = "bonne journée"
|
||||
// associate each character with its code
|
||||
val result = string.associateWith { char -> char.toInt() }
|
||||
val result = string.associateWith { char -> char.code }
|
||||
// notice each letter occurs only once
|
||||
assertPrints(result, "{b=98, o=111, n=110, e=101, =32, j=106, u=117, r=114, é=233}")
|
||||
}
|
||||
@@ -193,7 +193,7 @@ class Strings {
|
||||
val string = "bonne journée"
|
||||
// associate each character with its code
|
||||
val result = mutableMapOf<Char, Int>()
|
||||
string.associateWithTo(result) { char -> char.toInt() }
|
||||
string.associateWithTo(result) { char -> char.code }
|
||||
// notice each letter occurs only once
|
||||
assertPrints(result, "{b=98, o=111, n=110, e=101, =32, j=106, u=117, r=114, é=233}")
|
||||
}
|
||||
@@ -414,7 +414,7 @@ class Strings {
|
||||
@Sample
|
||||
fun map() {
|
||||
val string = "kotlin"
|
||||
assertPrints(string.map { it.toUpperCase() }, "[K, O, T, L, I, N]")
|
||||
assertPrints(string.map { it.uppercaseChar() }, "[K, O, T, L, I, N]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
|
||||
@@ -45,4 +45,5 @@ public expect fun Char(code: UShort): Char
|
||||
@SinceKotlin("1.5")
|
||||
@WasExperimental(ExperimentalStdlibApi::class)
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION")
|
||||
public inline val Char.code: Int get() = this.toInt()
|
||||
|
||||
@@ -149,16 +149,16 @@ class AbstractCollectionsTest {
|
||||
@Test
|
||||
fun abstractMutableMap() {
|
||||
val map = MutMap()
|
||||
for (e in 'a'..'z') map[e.toString()] = e.toInt()
|
||||
for (e in 'a'..'z') map[e.toString()] = e.code
|
||||
assertEquals(26, map.size)
|
||||
|
||||
map.remove("a")
|
||||
map.keys.remove("b")
|
||||
map.keys.removeAll { it == "c" }
|
||||
|
||||
map.values.remove('d'.toInt())
|
||||
map.values.remove('d'.code)
|
||||
assertTrue(map.containsKey("e"))
|
||||
assertTrue(map.containsValue('f'.toInt()))
|
||||
assertTrue(map.containsValue('f'.code))
|
||||
|
||||
compare(map.storage, map) {
|
||||
mapBehavior()
|
||||
|
||||
@@ -1156,7 +1156,7 @@ class ArraysTest {
|
||||
assertEquals(expected, FloatArray(size) { it.toFloat() }.scan("") { acc, e -> acc + e.toInt() })
|
||||
assertEquals(expected, DoubleArray(size) { it.toDouble() }.scan("") { acc, e -> acc + e.toInt() })
|
||||
assertEquals(
|
||||
expected.map { it.map { c -> c.toInt() % 2 == 0 }.joinToString(separator = "") },
|
||||
expected.map { it.map { c -> c.code % 2 == 0 }.joinToString(separator = "") },
|
||||
BooleanArray(size) { it % 2 == 0 }.scan("") { acc, e -> acc + e }
|
||||
)
|
||||
}
|
||||
@@ -1177,7 +1177,7 @@ class ArraysTest {
|
||||
assertEquals(expected, FloatArray(size) { it.toFloat() }.runningFold("") { acc, e -> acc + e.toInt() })
|
||||
assertEquals(expected, DoubleArray(size) { it.toDouble() }.runningFold("") { acc, e -> acc + e.toInt() })
|
||||
assertEquals(
|
||||
expected.map { it.map { c -> c.toInt() % 2 == 0 }.joinToString(separator = "") },
|
||||
expected.map { it.map { c -> c.code % 2 == 0 }.joinToString(separator = "") },
|
||||
BooleanArray(size) { it % 2 == 0 }.runningFold("") { acc, e -> acc + e }
|
||||
)
|
||||
}
|
||||
@@ -1199,7 +1199,7 @@ class ArraysTest {
|
||||
)
|
||||
assertEquals(
|
||||
expected,
|
||||
CharArray(size) { it.toChar() }.scanIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.toInt()}]" }
|
||||
CharArray(size) { Char(it) }.scanIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.code}]" }
|
||||
)
|
||||
assertEquals(
|
||||
expected,
|
||||
@@ -1222,7 +1222,7 @@ class ArraysTest {
|
||||
DoubleArray(size) { it.toDouble() }.scanIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.toInt()}]" }
|
||||
)
|
||||
assertEquals(
|
||||
expected.map { it.map { c -> if (c.isAsciiLetter()) c.toInt() % 2 != 0 else c }.joinToString(separator = "") },
|
||||
expected.map { it.map { c -> if (c.isAsciiLetter()) c.code % 2 != 0 else c }.joinToString(separator = "") },
|
||||
BooleanArray(size) { it % 2 == 0 }.scanIndexed("+") { index, acc, e -> "$acc[$index: $e]" }
|
||||
)
|
||||
}
|
||||
@@ -1244,7 +1244,7 @@ class ArraysTest {
|
||||
)
|
||||
assertEquals(
|
||||
expected,
|
||||
CharArray(size) { it.toChar() }.runningFoldIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.toInt()}]" }
|
||||
CharArray(size) { Char(it) }.runningFoldIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.code}]" }
|
||||
)
|
||||
assertEquals(
|
||||
expected,
|
||||
@@ -1267,7 +1267,7 @@ class ArraysTest {
|
||||
DoubleArray(size) { it.toDouble() }.runningFoldIndexed("+") { index, acc, e -> "$acc[$index: ${'a' + e.toInt()}]" }
|
||||
)
|
||||
assertEquals(
|
||||
expected.map { it.map { c -> if (c.isAsciiLetter()) c.toInt() % 2 != 0 else c }.joinToString(separator = "") },
|
||||
expected.map { it.map { c -> if (c.isAsciiLetter()) c.code % 2 != 0 else c }.joinToString(separator = "") },
|
||||
BooleanArray(size) { it % 2 == 0 }.runningFoldIndexed("+") { index, acc, e -> "$acc[$index: $e]" }
|
||||
)
|
||||
}
|
||||
@@ -1288,8 +1288,8 @@ class ArraysTest {
|
||||
ByteArray(size) { it.toByte() }.runningReduce { acc, e -> (acc + e).toByte() }
|
||||
)
|
||||
assertEquals(
|
||||
expected.map { it.toChar() },
|
||||
CharArray(size) { it.toChar() }.runningReduce { acc, e -> acc + e.toInt() }
|
||||
expected.map { Char(it) },
|
||||
CharArray(size) { Char(it) }.runningReduce { acc, e -> acc + e.code }
|
||||
)
|
||||
assertEquals(
|
||||
expected.map { it.toShort() },
|
||||
@@ -1332,8 +1332,8 @@ class ArraysTest {
|
||||
expected.map { it.toByte() },
|
||||
ByteArray(size) { it.toByte() }.runningReduceIndexed { index, acc, e -> (index * (acc + e)).toByte() })
|
||||
assertEquals(
|
||||
expected.map { it.toChar() },
|
||||
CharArray(size) { it.toChar() }.runningReduceIndexed { index, acc, e -> (index * (acc.toInt() + e.toInt())).toChar() }
|
||||
expected.map { Char(it) },
|
||||
CharArray(size) { Char(it) }.runningReduceIndexed { index, acc, e -> (index * (acc.code + e.code)).let(::Char) }
|
||||
)
|
||||
assertEquals(
|
||||
expected.map { it.toShort() },
|
||||
@@ -2177,7 +2177,7 @@ class ArraysTest {
|
||||
testShuffle(numbers.map(Int::toShort).toShortArray(), { shuffle() }, { toList() })
|
||||
testShuffle(numbers.map(Int::toFloat).toFloatArray(), { shuffle() }, { toList() })
|
||||
testShuffle(numbers.map(Int::toDouble).toDoubleArray(), { shuffle() }, { toList() })
|
||||
testShuffle(numbers.map(Int::toChar).toCharArray(), { shuffle() }, { toList() })
|
||||
testShuffle(numbers.map(::Char).toCharArray(), { shuffle() }, { toList() })
|
||||
testShuffle(numbers.map { it % 2 == 0 }.toBooleanArray(), { shuffle() }, { toList() })
|
||||
|
||||
testShuffle(numbers.map(Int::toUInt).toUIntArray(), { shuffle() }, { toList() })
|
||||
@@ -2207,7 +2207,7 @@ class ArraysTest {
|
||||
testShuffleR(numbers.map(Int::toShort).toShortArray(), { r -> shuffle(r) }, { toList() })
|
||||
testShuffleR(numbers.map(Int::toFloat).toFloatArray(), { r -> shuffle(r) }, { toList() })
|
||||
testShuffleR(numbers.map(Int::toDouble).toDoubleArray(), { r -> shuffle(r) }, { toList() })
|
||||
testShuffleR(numbers.map(Int::toChar).toCharArray(), { r -> shuffle(r) }, { toList() })
|
||||
testShuffleR(numbers.map(::Char).toCharArray(), { r -> shuffle(r) }, { toList() })
|
||||
testShuffleR(numbers.map { it % 2 == 0 }.toBooleanArray(), { r -> shuffle(r) }, { toList() })
|
||||
|
||||
testShuffleR(numbers.map(Int::toUInt).toUIntArray(), { r -> shuffle(r) }, { toList() })
|
||||
@@ -2244,7 +2244,7 @@ class ArraysTest {
|
||||
|
||||
testFailures(BooleanArray(5) { it % 2 == 0 }, BooleanArray::fill, true, 5)
|
||||
testFailures(ByteArray(5) { it.toByte() }, ByteArray::fill, 0.toByte(), 5)
|
||||
testFailures(CharArray(5) { it.toChar() }, CharArray::fill, 0.toChar(), 5)
|
||||
testFailures(CharArray(5) { Char(it) }, CharArray::fill, Char(0), 5)
|
||||
testFailures(FloatArray(5) { it.toFloat() }, FloatArray::fill, 0.0f, 5)
|
||||
testFailures(DoubleArray(5) { it.toDouble() }, DoubleArray::fill, 0.0, 5)
|
||||
testFailures(ShortArray(5) { it.toShort() }, ShortArray::fill, 0.toShort(), 5)
|
||||
@@ -2278,7 +2278,7 @@ class ArraysTest {
|
||||
|
||||
test(array, BooleanArray::fill, operations, IntArray::toBooleanArray, { this % 2 == 0 }, BooleanArray::contentEquals)
|
||||
test(array, ByteArray::fill, operations, IntArray::toByteArray, Int::toByte, ByteArray::contentEquals)
|
||||
test(array, CharArray::fill, operations, IntArray::toCharArray, Int::toChar, CharArray::contentEquals)
|
||||
test(array, CharArray::fill, operations, IntArray::toCharArray, ::Char, CharArray::contentEquals)
|
||||
test(array, FloatArray::fill, operations, IntArray::toFloatArray, Int::toFloat, FloatArray::contentEquals)
|
||||
test(array, DoubleArray::fill, operations, IntArray::toDoubleArray, Int::toDouble, DoubleArray::contentEquals)
|
||||
test(array, ShortArray::fill, operations, IntArray::toShortArray, Int::toShort, ShortArray::contentEquals)
|
||||
@@ -2297,7 +2297,7 @@ class ArraysTest {
|
||||
|
||||
private fun IntArray.toBooleanArray() = BooleanArray(size) { get(it) % 2 == 0 }
|
||||
private fun IntArray.toByteArray() = ByteArray(size) { get(it).toByte() }
|
||||
private fun IntArray.toCharArray() = CharArray(size) { get(it).toChar() }
|
||||
private fun IntArray.toCharArray() = CharArray(size) { Char(get(it)) }
|
||||
private fun IntArray.toFloatArray() = FloatArray(size) { get(it).toFloat() }
|
||||
private fun IntArray.toDoubleArray() = DoubleArray(size) { get(it).toDouble() }
|
||||
private fun IntArray.toShortArray() = ShortArray(size) { get(it).toShort() }
|
||||
|
||||
@@ -30,7 +30,7 @@ class GroupingTest {
|
||||
verifyGrouping(elements.asSequence().groupingBy(keySelector))
|
||||
|
||||
val charSeq = "some sequence of chars"
|
||||
verifyGrouping(charSeq.groupingBy { it.toInt() }, charSeq.toList(), charSeq.map { it.toInt() })
|
||||
verifyGrouping(charSeq.groupingBy { it.code }, charSeq.toList(), charSeq.map { it.code })
|
||||
}
|
||||
|
||||
// aggregate and aggregateTo operations are not tested, but they're used in every other operation
|
||||
|
||||
@@ -128,8 +128,8 @@ class NumbersTest {
|
||||
}
|
||||
|
||||
@Test fun charMinMaxValues() {
|
||||
assertTrue(Char.MIN_VALUE.toInt() == 0)
|
||||
assertTrue(Char.MAX_VALUE.toInt() > 0)
|
||||
assertTrue(Char.MIN_VALUE.code == 0)
|
||||
assertTrue(Char.MAX_VALUE.code > 0)
|
||||
|
||||
// overflow behavior
|
||||
expect(Char.MIN_VALUE) { Char.MAX_VALUE + one }
|
||||
|
||||
@@ -205,7 +205,7 @@ class CharTest {
|
||||
@Test
|
||||
fun charCategory() {
|
||||
for ((char, categoryCode) in charToCategory()) {
|
||||
assertEquals(categoryCode, char.category.code, "char code: ${char.toInt().toString(radix = 16)}")
|
||||
assertEquals(categoryCode, char.category.code, "char code: ${char.code.toString(radix = 16)}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class StringEncodingTest {
|
||||
|
||||
// https://youtrack.jetbrains.com/issue/KT-31614
|
||||
private fun string(vararg codeUnits: Int): String {
|
||||
return buildString { codeUnits.forEach { append(it.toChar()) } }
|
||||
return buildString { codeUnits.forEach { append(Char(it)) } }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user