From 85fe636d60f6bad7b298bc61d2c5126ec9601f58 Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Mon, 1 Mar 2021 23:55:34 +0300 Subject: [PATCH] Commonize Char.titlecaseChar() and Char.titlecase() #KT-44369 (cherry picked from commit 7b991613bb577a58235519b76ebec8b33270f783) --- .../kotlin/generated/_TitlecaseMappings.kt | 26 +++++++++++++++++++ .../src/main/kotlin/kotlin/text/Char.kt | 12 +++++++++ 2 files changed, 38 insertions(+) create mode 100644 kotlin-native/runtime/src/main/kotlin/generated/_TitlecaseMappings.kt diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_TitlecaseMappings.kt b/kotlin-native/runtime/src/main/kotlin/generated/_TitlecaseMappings.kt new file mode 100644 index 00000000000..f5c60fa79bc --- /dev/null +++ b/kotlin-native/runtime/src/main/kotlin/generated/_TitlecaseMappings.kt @@ -0,0 +1,26 @@ +/* + * 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.text + +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +// 4 ranges totally +@OptIn(ExperimentalStdlibApi::class) +internal fun Char.titlecaseCharImpl(): Char { + val code = this.toInt() + // 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() + } + // Lower case letters whose title case mapping equivalent is equal to the original letter + if (code in 0x10d0..0x10fa || code in 0x10fd..0x10ff) { + return this + } + return uppercaseChar() +} \ No newline at end of file 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 64922bc3aa4..887535cfef5 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/Char.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/Char.kt @@ -210,6 +210,18 @@ public actual fun Char.lowercaseChar(): Char = lowercaseCharImpl() @ExperimentalStdlibApi public actual fun Char.lowercase(): String = lowercaseImpl() +/** + * Converts this character to title case using Unicode mapping rules of the invariant locale. + * + * This function performs one-to-one character mapping. + * To support one-to-many character mapping use the [titlecase] function. + * If this character has no mapping equivalent, the result of calling [uppercaseChar] is returned. + * + * @sample samples.text.Chars.titlecase + */ +@SinceKotlin("1.4") +public actual fun Char.titlecaseChar(): Char = titlecaseCharImpl() + /** * Returns `true` if this character is a Unicode high-surrogate code unit (also known as leading-surrogate code unit). */