From 208b279d2b9d19f9f78f77b1e76751903c0ecb4a Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Sat, 8 Apr 2023 23:07:35 +0300 Subject: [PATCH] [K/N] Internalize CharCategory.value/valueOf As a part of efforts to stabilize K/N stdlib. --- .../tests/runtime/text/chars0.kt | 26 ------------------- .../src/kotlin/text/CharCategory.kt | 4 +-- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/kotlin-native/backend.native/tests/runtime/text/chars0.kt b/kotlin-native/backend.native/tests/runtime/text/chars0.kt index 3bdb1ebdf53..dc7ead95562 100644 --- a/kotlin-native/backend.native/tests/runtime/text/chars0.kt +++ b/kotlin-native/backend.native/tests/runtime/text/chars0.kt @@ -70,17 +70,6 @@ fun testCase() { } fun testCategory() { - assertEquals('\n'.category.value, CharCategory.CONTROL.value) - assertEquals('1'.category.value, CharCategory.DECIMAL_DIGIT_NUMBER.value) - assertEquals(' '.category.value, CharCategory.SPACE_SEPARATOR.value) - assertEquals('a'.category.value, CharCategory.LOWERCASE_LETTER.value) - assertEquals('A'.category.value, CharCategory.UPPERCASE_LETTER.value) - assertEquals('<'.category.value, CharCategory.MATH_SYMBOL.value) - assertEquals(';'.category.value, CharCategory.OTHER_PUNCTUATION.value) - assertEquals('_'.category.value, CharCategory.CONNECTOR_PUNCTUATION.value) - assertEquals('$'.category.value, CharCategory.CURRENCY_SYMBOL.value) - assertEquals('\u2029'.category.value, CharCategory.PARAGRAPH_SEPARATOR.value) - assertTrue('\n' in CharCategory.CONTROL) assertTrue('1' in CharCategory.DECIMAL_DIGIT_NUMBER) assertTrue(' ' in CharCategory.SPACE_SEPARATOR) @@ -91,21 +80,6 @@ fun testCategory() { assertTrue('_' in CharCategory.CONNECTOR_PUNCTUATION) assertTrue('$' in CharCategory.CURRENCY_SYMBOL) assertTrue('\u2029' in CharCategory.PARAGRAPH_SEPARATOR) - - try { - CharCategory.valueOf(-1) - throw AssertionError() - } catch (e: IllegalArgumentException) {} - - try { - CharCategory.valueOf(31) - throw AssertionError() - } catch (e: IllegalArgumentException) {} - - try { - CharCategory.valueOf(17) - throw AssertionError() - } catch (e: IllegalArgumentException) {} } fun testIsHighSurrogate() { diff --git a/libraries/stdlib/native-wasm/src/kotlin/text/CharCategory.kt b/libraries/stdlib/native-wasm/src/kotlin/text/CharCategory.kt index c7def3375de..9ebf83aa1b3 100644 --- a/libraries/stdlib/native-wasm/src/kotlin/text/CharCategory.kt +++ b/libraries/stdlib/native-wasm/src/kotlin/text/CharCategory.kt @@ -7,7 +7,7 @@ package kotlin.text /** * Represents the character general category in the Unicode specification. */ -public actual enum class CharCategory(public val value: Int, public actual val code: String) { +public actual enum class CharCategory(internal val value: Int, public actual val code: String) { /** * General category "Cn" in the Unicode specification. */ @@ -164,7 +164,7 @@ public actual enum class CharCategory(public val value: Int, public actual val c public actual operator fun contains(char: Char): Boolean = char.getCategoryValue() == this.value public companion object { - public fun valueOf(category: Int): CharCategory = + internal fun valueOf(category: Int): CharCategory = when (category) { in 0..16 -> values()[category] in 18..30 -> values()[category - 1]