toCodePoint
Converts this Int value to a CodePoint.
Unlike CodePoint class constructor, this function does not throw an exception when the value is outside the valid Unicode code point range 0..0x10FFFF, but instead wraps that value around using modulo arithmetic to ensure the result is within the valid range.
Since Kotlin
2.5Return
A CodePoint with the code equal to this integer value modulo 0x10FFFF + 1.
See also
Samples
import kotlin.text.unicode.*
import kotlin.test.*
fun main() {
//sampleStart
val validCodePoint = 0x1F60B.toCodePoint() // 😋
println(validCodePoint) // 😋
val wrappedCodePoint = (-1).toCodePoint()
println(wrappedCodePoint.code.toHexString()) // 0010ffff
//sampleEnd
}Content copied to clipboard
Converts this Char to a CodePoint.
The resulting code point has the same code as this Char that is always in the range 0x0000 to 0xFFFF.
Since Kotlin
2.5Return
A CodePoint with the same numeric value as this character.
See also
Samples
import kotlin.text.unicode.*
import kotlin.test.*
fun main() {
//sampleStart
val char = 'Ü'
val codePoint1 = char.toCodePoint()
// or
val codePoint2 = CodePoint.fromChar(char)
println(codePoint1) // Ü
println(codePoint2) // Ü
// conversion from chars always result in basic code points
println(codePoint1.size) // 1
println("codePoint1.isBasic is ${codePoint1.isBasic}") // true
//sampleEnd
}Content copied to clipboard