diff --git a/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeMem.kt b/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeMem.kt index c39f1364981..3dd23a8867f 100644 --- a/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeMem.kt +++ b/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeMem.kt @@ -81,7 +81,7 @@ internal object nativeMemUtils { val sourceArray = source.reinterpret().ptr var index = 0 while (index < length) { - dest[index] = sourceArray[index].toChar() + dest[index] = sourceArray[index].toInt().toChar() ++index } } @@ -91,7 +91,7 @@ internal object nativeMemUtils { val destArray = dest.reinterpret().ptr var index = 0 while (index < length) { - destArray[index] = source[index].toShort() + destArray[index] = source[index].code.toShort() ++index } } @@ -148,7 +148,7 @@ public fun CPointer.toKStringFromUtf16(): String { val chars = kotlin.CharArray(length) var index = 0 while (index < length) { - chars[index] = nativeBytes[index].toShort().toChar() + chars[index] = nativeBytes[index].toInt().toChar() ++index } return chars.concatToString() diff --git a/kotlin-native/backend.native/tests/stdlib_external/text/StringNativeTest.kt b/kotlin-native/backend.native/tests/stdlib_external/text/StringNativeTest.kt index 2a8f46d5017..8115f7be039 100644 --- a/kotlin-native/backend.native/tests/stdlib_external/text/StringNativeTest.kt +++ b/kotlin-native/backend.native/tests/stdlib_external/text/StringNativeTest.kt @@ -56,7 +56,7 @@ class StringNativeTest { } fun Char.hex(): String { - return toInt().toString(16).padStart(4, '0') + return code.toString(16).padStart(4, '0') } val sigma = '\u03A3' diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_CharCategories.kt b/kotlin-native/runtime/src/main/kotlin/generated/_CharCategories.kt index 541a012d5fd..0e54def202f 100644 --- a/kotlin-native/runtime/src/main/kotlin/generated/_CharCategories.kt +++ b/kotlin-native/runtime/src/main/kotlin/generated/_CharCategories.kt @@ -173,7 +173,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(rangeStart, ch) val start = rangeStart[index] diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_DigitChars.kt b/kotlin-native/runtime/src/main/kotlin/generated/_DigitChars.kt index ac793a85af0..729b79f15d4 100644 --- a/kotlin-native/runtime/src/main/kotlin/generated/_DigitChars.kt +++ b/kotlin-native/runtime/src/main/kotlin/generated/_DigitChars.kt @@ -39,7 +39,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(rangeStart, ch) val high = rangeStart[index] + 9 return ch <= high diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_LetterChars.kt b/kotlin-native/runtime/src/main/kotlin/generated/_LetterChars.kt index c18debca831..5b54e6ed224 100644 --- a/kotlin-native/runtime/src/main/kotlin/generated/_LetterChars.kt +++ b/kotlin-native/runtime/src/main/kotlin/generated/_LetterChars.kt @@ -89,7 +89,7 @@ internal fun Char.isUpperCaseImpl(): Boolean { * - `0` otherwise. */ private fun Char.getLetterType(): Int { - val ch = this.toInt() + val ch = this.code val index = binarySearchRange(rangeStart, ch) val rangeStart = rangeStart[index] diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_LowercaseMappings.kt b/kotlin-native/runtime/src/main/kotlin/generated/_LowercaseMappings.kt index 542cac8fe7c..927a828ff49 100644 --- a/kotlin-native/runtime/src/main/kotlin/generated/_LowercaseMappings.kt +++ b/kotlin-native/runtime/src/main/kotlin/generated/_LowercaseMappings.kt @@ -49,5 +49,5 @@ internal fun Int.lowercaseCodePoint(): Int { } internal fun Char.lowercaseCharImpl(): Char { - return toInt().lowercaseCodePoint().toChar() + return code.lowercaseCodePoint().toChar() } diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_OneToManyUppercaseMappings.kt b/kotlin-native/runtime/src/main/kotlin/generated/_OneToManyUppercaseMappings.kt index 8a047c2ff98..e9851f6788f 100644 --- a/kotlin-native/runtime/src/main/kotlin/generated/_OneToManyUppercaseMappings.kt +++ b/kotlin-native/runtime/src/main/kotlin/generated/_OneToManyUppercaseMappings.kt @@ -35,7 +35,7 @@ internal fun Char.oneToManyUppercase(): String? { return null } - val code = this.toInt() + val code = this.code val index = binarySearchRange(keys, code) if (keys[index] == code) { return values[index] diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_StringLowercase.kt b/kotlin-native/runtime/src/main/kotlin/generated/_StringLowercase.kt index b45f11d8ce8..a6b19050e37 100644 --- a/kotlin-native/runtime/src/main/kotlin/generated/_StringLowercase.kt +++ b/kotlin-native/runtime/src/main/kotlin/generated/_StringLowercase.kt @@ -28,7 +28,7 @@ private val casedEnd = intArrayOf( // 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, @@ -65,7 +65,7 @@ private val caseIgnorableEnd = intArrayOf( // 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, @@ -86,7 +86,7 @@ private fun String.codePointBefore(index: Int): Int { return Char.toCodePoint(high, low) } } - return low.toInt() + return low.code } // \p{cased} (\p{case-ignorable})* Sigma !( (\p{case-ignorable})* \p{cased} ) diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_StringUppercase.kt b/kotlin-native/runtime/src/main/kotlin/generated/_StringUppercase.kt index b806ccb2588..cd1f2b04424 100644 --- a/kotlin-native/runtime/src/main/kotlin/generated/_StringUppercase.kt +++ b/kotlin-native/runtime/src/main/kotlin/generated/_StringUppercase.kt @@ -18,7 +18,7 @@ internal fun String.codePointAt(index: Int): Int { return Char.toCodePoint(high, low) } } - return high.toInt() + return high.code } internal fun Int.charCount(): Int = if (this >= Char.MIN_SUPPLEMENTARY_CODE_POINT) 2 else 1 diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_TitlecaseMappings.kt b/kotlin-native/runtime/src/main/kotlin/generated/_TitlecaseMappings.kt index f5c60fa79bc..a6ad6ae2bad 100644 --- a/kotlin-native/runtime/src/main/kotlin/generated/_TitlecaseMappings.kt +++ b/kotlin-native/runtime/src/main/kotlin/generated/_TitlecaseMappings.kt @@ -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 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() diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_UppercaseMappings.kt b/kotlin-native/runtime/src/main/kotlin/generated/_UppercaseMappings.kt index dbf18dade46..c9dfffb58bc 100644 --- a/kotlin-native/runtime/src/main/kotlin/generated/_UppercaseMappings.kt +++ b/kotlin-native/runtime/src/main/kotlin/generated/_UppercaseMappings.kt @@ -68,5 +68,5 @@ internal fun Int.uppercaseCodePoint(): Int { } internal fun Char.uppercaseCharImpl(): Char { - return toInt().uppercaseCodePoint().toChar() + return code.uppercaseCodePoint().toChar() } diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_WhitespaceChars.kt b/kotlin-native/runtime/src/main/kotlin/generated/_WhitespaceChars.kt index fe55745b8bd..5ab0a1420d0 100644 --- a/kotlin-native/runtime/src/main/kotlin/generated/_WhitespaceChars.kt +++ b/kotlin-native/runtime/src/main/kotlin/generated/_WhitespaceChars.kt @@ -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 diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/Char.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/Char.kt index d3c424e82e2..5b2d6c18186 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/Char.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/Char.kt @@ -24,13 +24,13 @@ public class Char private constructor() : Comparable { /** Adds the other Int value to this value resulting a Char. */ public inline operator fun plus(other: Int): Char = - (this.toInt() + other).toChar() + (this.code + other).toChar() /** Subtracts the other Char value from this value resulting an Int. */ public inline operator fun minus(other: Char): Int = - this.toInt() - other.toInt() + this.code - other.code /** Subtracts the other Int value from this value resulting a Char. */ public inline operator fun minus(other: Int): Char = - (this.toInt() - other).toChar() + (this.code - other).toChar() /** Increments this value. */ @TypedIntrinsic(IntrinsicType.INC) @@ -45,23 +45,35 @@ public class Char private constructor() : Comparable { } /** 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") @TypedIntrinsic(IntrinsicType.INT_TRUNCATE) external public fun toByte(): Byte /** Returns the value of this character as a `Char`. */ public inline 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") @TypedIntrinsic(IntrinsicType.ZERO_EXTEND) external public fun toShort(): Short /** 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") @TypedIntrinsic(IntrinsicType.ZERO_EXTEND) external public fun toInt(): Int /** 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") @TypedIntrinsic(IntrinsicType.ZERO_EXTEND) external public fun toLong(): Long /** 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") @TypedIntrinsic(IntrinsicType.UNSIGNED_TO_FLOAT) external public fun toFloat(): Float /** 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") @TypedIntrinsic(IntrinsicType.UNSIGNED_TO_FLOAT) external public fun toDouble(): Double @@ -155,7 +167,7 @@ public class Char private constructor() : Comparable { external public override fun toString(): String public override fun hashCode(): Int { - return this.toInt(); + return this.code } } diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/Primitives.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/Primitives.kt index 4c9f239532e..5e794d24228 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/Primitives.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/Primitives.kt @@ -203,6 +203,8 @@ public final class Byte private constructor() : Number(), Comparable { * 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") @TypedIntrinsic(IntrinsicType.SIGN_EXTEND) external public override fun toChar(): Char /** @@ -494,6 +496,8 @@ public final class Short private constructor() : Number(), Comparable { * 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()")) + @DeprecatedSinceKotlin(warningSince = "1.5") @TypedIntrinsic(IntrinsicType.ZERO_EXTEND) external public override fun toChar(): Char @@ -1080,6 +1084,8 @@ public final class Long private constructor() : Number(), Comparable { * * The resulting `Char` code is represented by the least significant 16 bits of this `Long` value. */ + @Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()")) + @DeprecatedSinceKotlin(warningSince = "1.5") @TypedIntrinsic(IntrinsicType.INT_TRUNCATE) external public override fun toChar(): Char /** @@ -1355,6 +1361,8 @@ public final class Float private constructor() : Number(), Comparable { * * 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 = this.toInt().toChar() /** @@ -1631,6 +1639,8 @@ public final class Double private constructor() : Number(), Comparable { * * 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 = this.toInt().toChar() /** diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt index 2913c1f39b0..3437fda6b8e 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt @@ -184,7 +184,7 @@ internal fun checkProgressionStep(step: Long) = @PublishedApi internal fun getProgressionLast(start: Char, end: Char, step: Int): Char = - getProgressionLast(start.toInt(), end.toInt(), step).toChar() + getProgressionLast(start.code, end.code, step).toChar() @PublishedApi internal fun getProgressionLast(start: Int, end: Int, step: Int): Int = diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/ProgressionIterators.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/ProgressionIterators.kt index 8c8441a6800..5cbbb654dd6 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/ProgressionIterators.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/ProgressionIterators.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. + * 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.ranges @@ -10,9 +10,9 @@ package kotlin.ranges * @property step the number by which the value is incremented on each step. */ internal class CharProgressionIterator(first: Char, last: Char, val step: Int) : CharIterator() { - private val finalElement = last.toInt() + private val finalElement: Int = last.code private var hasNext: Boolean = if (step > 0) first <= last else first >= last - private var next = if (hasNext) first.toInt() else finalElement + private var next: Int = if (hasNext) first.code else finalElement override fun hasNext(): Boolean = hasNext @@ -34,9 +34,9 @@ internal class CharProgressionIterator(first: Char, last: Char, val step: Int) : * @property step the number by which the value is incremented on each step. */ internal class IntProgressionIterator(first: Int, last: Int, val step: Int) : IntIterator() { - private val finalElement = last + private val finalElement: Int = last private var hasNext: Boolean = if (step > 0) first <= last else first >= last - private var next = if (hasNext) first else finalElement + private var next: Int = if (hasNext) first else finalElement override fun hasNext(): Boolean = hasNext @@ -58,9 +58,9 @@ internal class IntProgressionIterator(first: Int, last: Int, val step: Int) : In * @property step the number by which the value is incremented on each step. */ internal class LongProgressionIterator(first: Long, last: Long, val step: Long) : LongIterator() { - private val finalElement = last + private val finalElement: Long = last private var hasNext: Boolean = if (step > 0) first <= last else first >= last - private var next = if (hasNext) first else finalElement + private var next: Long = if (hasNext) first else finalElement override fun hasNext(): Boolean = hasNext @@ -75,4 +75,5 @@ internal class LongProgressionIterator(first: Long, last: Long, val step: Long) } return value } -} \ No newline at end of file +} + diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Progressions.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Progressions.kt index ff97fc4d1e4..665091f2a56 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Progressions.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Progressions.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. + * 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. */ // A copy-paste from kotlin/core/builtins/src/kotlin/Progressions.kt @@ -13,12 +13,12 @@ import kotlin.internal.getProgressionLastElement * A progression of values of type `Char`. */ public open class CharProgression -internal constructor -( - start: Char, - endInclusive: Char, - step: Int -) : Iterable { + internal constructor + ( + start: Char, + endInclusive: Char, + step: Int + ) : Iterable { init { if (step == 0) throw kotlin.IllegalArgumentException("Step must be non-zero.") if (step == Int.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must be greater than Int.MIN_VALUE to avoid overflow on negation.") @@ -32,7 +32,7 @@ internal constructor /** * The last element in the progression. */ - public val last: Char = getProgressionLastElement(start.toInt(), endInclusive.toInt(), step).toChar() + public val last: Char = getProgressionLastElement(start.code, endInclusive.code, step).toChar() /** * The step of the progression. @@ -41,15 +41,20 @@ internal constructor override fun iterator(): CharIterator = CharProgressionIterator(first, last, step) - /** Checks if the progression is empty. */ + /** + * Checks if the progression is empty. + + * Progression with a positive step is empty if its first element is greater than the last element. + * Progression with a negative step is empty if its first element is less than the last element. + */ public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last override fun equals(other: Any?): Boolean = - other is CharProgression && (isEmpty() && other.isEmpty() || - first == other.first && last == other.last && step == other.step) + other is CharProgression && (isEmpty() && other.isEmpty() || + first == other.first && last == other.last && step == other.step) override fun hashCode(): Int = - if (isEmpty()) -1 else (31 * (31 * first.toInt() + last.toInt()) + step) + if (isEmpty()) -1 else (31 * (31 * first.code + last.code) + step) override fun toString(): String = if (step > 0) "$first..$last step $step" else "$first downTo $last step ${-step}" @@ -70,12 +75,12 @@ internal constructor * A progression of values of type `Int`. */ public open class IntProgression -internal constructor -( - start: Int, - endInclusive: Int, - step: Int -) : Iterable { + internal constructor + ( + start: Int, + endInclusive: Int, + step: Int + ) : Iterable { init { if (step == 0) throw kotlin.IllegalArgumentException("Step must be non-zero.") if (step == Int.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must be greater than Int.MIN_VALUE to avoid overflow on negation.") @@ -89,7 +94,7 @@ internal constructor /** * The last element in the progression. */ - public val last: Int = getProgressionLastElement(start.toInt(), endInclusive.toInt(), step).toInt() + public val last: Int = getProgressionLastElement(start, endInclusive, step) /** * The step of the progression. @@ -98,15 +103,20 @@ internal constructor override fun iterator(): IntIterator = IntProgressionIterator(first, last, step) - /** Checks if the progression is empty. */ + /** + * Checks if the progression is empty. + + * Progression with a positive step is empty if its first element is greater than the last element. + * Progression with a negative step is empty if its first element is less than the last element. + */ public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last override fun equals(other: Any?): Boolean = - other is IntProgression && (isEmpty() && other.isEmpty() || - first == other.first && last == other.last && step == other.step) + other is IntProgression && (isEmpty() && other.isEmpty() || + first == other.first && last == other.last && step == other.step) override fun hashCode(): Int = - if (isEmpty()) -1 else (31 * (31 * first + last) + step) + if (isEmpty()) -1 else (31 * (31 * first + last) + step) override fun toString(): String = if (step > 0) "$first..$last step $step" else "$first downTo $last step ${-step}" @@ -127,12 +137,12 @@ internal constructor * A progression of values of type `Long`. */ public open class LongProgression -internal constructor -( - start: Long, - endInclusive: Long, - step: Long -) : Iterable { + internal constructor + ( + start: Long, + endInclusive: Long, + step: Long + ) : Iterable { init { if (step == 0L) throw kotlin.IllegalArgumentException("Step must be non-zero.") if (step == Long.MIN_VALUE) throw kotlin.IllegalArgumentException("Step must be greater than Long.MIN_VALUE to avoid overflow on negation.") @@ -146,7 +156,7 @@ internal constructor /** * The last element in the progression. */ - public val last: Long = getProgressionLastElement(start.toLong(), endInclusive.toLong(), step).toLong() + public val last: Long = getProgressionLastElement(start, endInclusive, step) /** * The step of the progression. @@ -155,15 +165,20 @@ internal constructor override fun iterator(): LongIterator = LongProgressionIterator(first, last, step) - /** Checks if the progression is empty. */ + /** + * Checks if the progression is empty. + + * Progression with a positive step is empty if its first element is greater than the last element. + * Progression with a negative step is empty if its first element is less than the last element. + */ public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last override fun equals(other: Any?): Boolean = - other is LongProgression && (isEmpty() && other.isEmpty() || - first == other.first && last == other.last && step == other.step) + other is LongProgression && (isEmpty() && other.isEmpty() || + first == other.first && last == other.last && step == other.step) override fun hashCode(): Int = - if (isEmpty()) -1 else (31 * (31 * (first xor (first ushr 32)) + (last xor (last ushr 32))) + (step xor (step ushr 32))).toInt() + if (isEmpty()) -1 else (31 * (31 * (first xor (first ushr 32)) + (last xor (last ushr 32))) + (step xor (step ushr 32))).toInt() override fun toString(): String = if (step > 0) "$first..$last step $step" else "$first downTo $last step ${-step}" @@ -178,4 +193,5 @@ internal constructor */ public fun fromClosedRange(rangeStart: Long, rangeEnd: Long, step: Long): LongProgression = LongProgression(rangeStart, rangeEnd, step) } -} \ No newline at end of file +} + diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Range.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Range.kt index 3003d0f1176..640336556cb 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Range.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Range.kt @@ -27,6 +27,8 @@ public interface ClosedRange> { /** * Checks whether the range is empty. + + * The range is empty if its start value is greater than the end value. */ public fun isEmpty(): Boolean = start > endInclusive } diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Ranges.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Ranges.kt index 0243ad46b94..1b18a308cb0 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Ranges.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/ranges/Ranges.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. + * 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.ranges @@ -14,14 +14,19 @@ public class CharRange(start: Char, endInclusive: Char) : CharProgression(start, override fun contains(value: Char): Boolean = first <= value && value <= last + /** + * Checks whether the range is empty. + + * The range is empty if its start value is greater than the end value. + */ override fun isEmpty(): Boolean = first > last override fun equals(other: Any?): Boolean = - other is CharRange && (isEmpty() && other.isEmpty() || - first == other.first && last == other.last) + other is CharRange && (isEmpty() && other.isEmpty() || + first == other.first && last == other.last) override fun hashCode(): Int = - if (isEmpty()) -1 else (31 * first.toInt() + last.toInt()) + if (isEmpty()) -1 else (31 * first.code + last.code) override fun toString(): String = "$first..$last" @@ -40,14 +45,19 @@ public class IntRange(start: Int, endInclusive: Int) : IntProgression(start, end override fun contains(value: Int): Boolean = first <= value && value <= last + /** + * Checks whether the range is empty. + + * The range is empty if its start value is greater than the end value. + */ override fun isEmpty(): Boolean = first > last override fun equals(other: Any?): Boolean = - other is IntRange && (isEmpty() && other.isEmpty() || - first == other.first && last == other.last) + other is IntRange && (isEmpty() && other.isEmpty() || + first == other.first && last == other.last) override fun hashCode(): Int = - if (isEmpty()) -1 else (31 * first + last) + if (isEmpty()) -1 else (31 * first + last) override fun toString(): String = "$first..$last" @@ -66,14 +76,19 @@ public class LongRange(start: Long, endInclusive: Long) : LongProgression(start, override fun contains(value: Long): Boolean = first <= value && value <= last + /** + * Checks whether the range is empty. + + * The range is empty if its start value is greater than the end value. + */ override fun isEmpty(): Boolean = first > last override fun equals(other: Any?): Boolean = - other is LongRange && (isEmpty() && other.isEmpty() || - first == other.first && last == other.last) + other is LongRange && (isEmpty() && other.isEmpty() || + first == other.first && last == other.last) override fun hashCode(): Int = - if (isEmpty()) -1 else (31 * (first xor (first ushr 32)) + (last xor (last ushr 32))).toInt() + if (isEmpty()) -1 else (31 * (first xor (first ushr 32)) + (last xor (last ushr 32))).toInt() override fun toString(): String = "$first..$last" @@ -82,3 +97,4 @@ public class LongRange(start: Long, endInclusive: Long) : LongProgression(start, public val EMPTY: LongRange = LongRange(1, 0) } } + diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/Char.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/Char.kt index adf06662a9e..991f49eb48b 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/Char.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/Char.kt @@ -264,6 +264,7 @@ internal actual fun checkRadix(radix: Int): Int { /** Converts a unicode code point to lower case. */ internal fun Char.Companion.toLowerCase(codePoint: Int): Int = if (codePoint < MIN_SUPPLEMENTARY_CODE_POINT) { + @Suppress("DEPRECATION") codePoint.toChar().toLowerCase().toInt() } else { codePoint // TODO: Implement this transformation for supplementary codepoints. @@ -272,19 +273,23 @@ internal fun Char.Companion.toLowerCase(codePoint: Int): Int = /** Converts a unicode code point to upper case. */ internal fun Char.Companion.toUpperCase(codePoint: Int): Int = if (codePoint < MIN_SUPPLEMENTARY_CODE_POINT) { + @Suppress("DEPRECATION") codePoint.toChar().toUpperCase().toInt() } else { codePoint // TODO: Implement this transformation for supplementary codepoints. } /** Converts a surrogate pair to a unicode code point. Doesn't validate that the characters are a valid surrogate pair. */ +// TODO: Consider removing from public API public fun Char.Companion.toCodePoint(high: Char, low: Char): Int = (((high - MIN_HIGH_SURROGATE) shl 10) or (low - MIN_LOW_SURROGATE)) + 0x10000 /** Checks if the codepoint specified is a supplementary codepoint or not. */ +// TODO: Consider removing from public API public fun Char.Companion.isSupplementaryCodePoint(codepoint: Int): Boolean = codepoint in MIN_SUPPLEMENTARY_CODE_POINT..MAX_CODE_POINT +// TODO: Consider removing from public API public fun Char.Companion.isSurrogatePair(high: Char, low: Char): Boolean = high.isHighSurrogate() && low.isLowSurrogate() /** @@ -292,6 +297,8 @@ public fun Char.Companion.isSurrogatePair(high: Char, low: Char): Boolean = high * return an array with one element otherwise it will return an array A with a high surrogate in A[0] and * a low surrogate in A[1]. */ +// TODO: Consider removing from public API +@Suppress("DEPRECATION") public fun Char.Companion.toChars(codePoint: Int): CharArray = when { codePoint in 0 until MIN_SUPPLEMENTARY_CODE_POINT -> charArrayOf(codePoint.toChar()) diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt index 0b120951773..9f361ceb5d6 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt @@ -20,6 +20,7 @@ * limitations under the License. */ +@file:Suppress("DEPRECATION") // Char.toInt() package kotlin.text.regex import kotlin.collections.associate diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/AbstractLineTerminator.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/AbstractLineTerminator.kt index fc145cc4be5..aab8b1fdcd0 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/AbstractLineTerminator.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/AbstractLineTerminator.kt @@ -20,6 +20,7 @@ * limitations under the License. */ +@file:Suppress("DEPRECATION") // Char.toInt() package kotlin.text.regex private object unixLT : AbstractLineTerminator() { diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/CharClass.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/CharClass.kt index 0915c5cf8a6..ed16b6ee623 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/CharClass.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/CharClass.kt @@ -19,7 +19,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +@file:Suppress("DEPRECATION") // Char.toInt() package kotlin.text.regex /** diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/Lexer.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/Lexer.kt index ccb088c87f3..d28094d5a73 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/Lexer.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/Lexer.kt @@ -21,6 +21,7 @@ */ // TODO: Licenses. +@file:Suppress("DEPRECATION") // Char.toInt() package kotlin.text.regex // Access to the decomposition tables. ========================================================================= diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt index c1a46eb0f76..9eaad27b09f 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt @@ -20,6 +20,7 @@ * limitations under the License. */ +@file:Suppress("DEPRECATION") // Char.toInt() package kotlin.text.regex /** Represents a compiled pattern used by [Regex] for matching, searching, or replacing strings. */ diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/AbstractSet.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/AbstractSet.kt index 897b4d61f9b..c48a27f326b 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/AbstractSet.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/AbstractSet.kt @@ -41,6 +41,7 @@ internal abstract class AbstractSet(val type: Int = 0) { const val TYPE_LEAF = 1 shl 0 const val TYPE_FSET = 1 shl 1 const val TYPE_QUANT = 1 shl 3 + @Suppress("DEPRECATION") const val TYPE_DOTSET = 0x80000000.toInt() or '.'.toInt() val dummyNext = object : AbstractSet() { diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/DecomposedCharSet.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/DecomposedCharSet.kt index ec0e70a9221..825e78a67b1 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/DecomposedCharSet.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/DecomposedCharSet.kt @@ -139,9 +139,11 @@ open internal class DecomposedCharSet( curChar = Char.toCodePoint(high, low) readCharsForCodePoint = 2 } else { + @Suppress("DEPRECATION") curChar = high.toInt() } } else { + @Suppress("DEPRECATION") curChar = testString[index].toInt() } diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt index 058d0bcaddc..d805d62ae79 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt @@ -20,6 +20,7 @@ * limitations under the License. */ +@file:Suppress("DEPRECATION") // Char.toInt() package kotlin.text.regex import kotlin.text.* diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/RangeSet.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/RangeSet.kt index 3205c35bfc2..2e8a23c659a 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/RangeSet.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/RangeSet.kt @@ -42,6 +42,7 @@ open internal class RangeSet(charClass: AbstractCharClass, val ignoreCase: Boole get() = "range:" + (if (chars.alt) "^ " else " ") + chars.toString() override fun first(set: AbstractSet): Boolean { + @Suppress("DEPRECATION") return when (set) { is CharSet -> AbstractCharClass.intersects(chars, set.char.toInt()) is RangeSet -> AbstractCharClass.intersects(chars, set.chars) diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/SupplementaryRangeSet.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/SupplementaryRangeSet.kt index c73a7db2633..d64e32a2060 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/SupplementaryRangeSet.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/regex/sets/SupplementaryRangeSet.kt @@ -137,6 +137,7 @@ open internal class SupplementaryRangeSet(charClass: AbstractCharClass, val igno override fun first(set: AbstractSet): Boolean { + @Suppress("DEPRECATION") return when(set) { is SupplementaryCharSet -> AbstractCharClass.intersects(chars, set.codePoint) is CharSet -> AbstractCharClass.intersects(chars, set.char.toInt())