Commonize Char.titlecaseChar() and Char.titlecase() #KT-44369
This commit is contained in:
@@ -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 <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()
|
||||
}
|
||||
// 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()
|
||||
}
|
||||
@@ -79,6 +79,19 @@ public actual fun Char.uppercaseChar(): Char {
|
||||
@kotlin.internal.InlineOnly
|
||||
public actual inline fun Char.uppercase(): String = toString().asDynamic().toUpperCase() as String
|
||||
|
||||
/**
|
||||
* 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")
|
||||
@ExperimentalStdlibApi
|
||||
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).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user