size
The number of Char values needed to represent this code point.
Returns 1 for basic (BMP) code points in the range 0x0000 to 0xFFFF, which can be represented by a single Char. Returns 2 for supplementary code points in the range 0x10000 to 0x10FFFF, which can be represented by a surrogate pair of two Char values.
Since Kotlin
2.5Samples
import kotlin.text.unicode.*
import kotlin.test.*
fun main() {
//sampleStart
val basicCodePoint = 'K'.toCodePoint()
println(basicCodePoint.toString()) // K
println(basicCodePoint.code.toHexString()) // 0000004b
println(basicCodePoint.size) // 1
println("basicCodePoint.isBasic is ${basicCodePoint.isBasic}") // true
println("basicCodePoint.isSupplementary is ${basicCodePoint.isSupplementary}") // false
val supplementaryCodePoint = CodePoint(0x1F60B) // 😋
println(supplementaryCodePoint.toString()) // 😋
println(supplementaryCodePoint.code.toHexString()) // 0001f60b
println(supplementaryCodePoint.size) // 2
println("supplementaryCodePoint.isBasic is ${supplementaryCodePoint.isBasic}") // false
println("supplementaryCodePoint.isSupplementary is ${supplementaryCodePoint.isSupplementary}") // true
//sampleEnd
}Content copied to clipboard