toSurrogatePair
Converts this supplementary code point to a surrogate pair.
This method is only applicable to supplementary code points in the range 0x10000 to 0x10FFFF. The returned pair contains the high surrogate as the first component and the low surrogate as the second component.
Since Kotlin
2.5Return
A Pair of Char values representing the high and low surrogates.
See also
Throws
if this is a basic (BMP) code point.
Samples
import kotlin.text.unicode.*
import kotlin.test.*
fun main() {
//sampleStart
val supplementaryCodePoint = CodePoint(0x1F60B) // π
val [high, low] = supplementaryCodePoint.toSurrogatePair()
// this code point is represented by surrogate pair \uD83D \uDE0B
println(high.code.toHexString()) // 0000d83d
println(low.code.toHexString()) // 0000de0b
// or
val string = supplementaryCodePoint.toSurrogatePair { h, l -> "$h$l" }
println(string) // π
val basicCodePoint = 'Γ'.toCodePoint()
// basicCodePoint.toSurrogatePair() // will fail with IllegalArgumentException
//sampleEnd
}Converts this supplementary code point to a surrogate pair and applies the given action to its components.
This method is only applicable to supplementary code points in the range 0x10000 to 0x10FFFF. The action function receives the high surrogate as the first parameter and the low surrogate as the second parameter.
Since Kotlin
2.5Return
The result of applying action to the high and low surrogates.
Parameters
See also
Throws
if this is a basic (BMP) code point.
Samples
import kotlin.text.unicode.*
import kotlin.test.*
fun main() {
//sampleStart
val supplementaryCodePoint = CodePoint(0x1F60B) // π
val [high, low] = supplementaryCodePoint.toSurrogatePair()
// this code point is represented by surrogate pair \uD83D \uDE0B
println(high.code.toHexString()) // 0000d83d
println(low.code.toHexString()) // 0000de0b
// or
val string = supplementaryCodePoint.toSurrogatePair { h, l -> "$h$l" }
println(string) // π
val basicCodePoint = 'Γ'.toCodePoint()
// basicCodePoint.toSurrogatePair() // will fail with IllegalArgumentException
//sampleEnd
}