CodePoint
Represents a Unicode code point, which is a numerical value that uniquely identifies a character in the Unicode standard.
A code point code is an integer value in the range 0x0000 to 0x10FFFF (inclusive).
Code points are divided into two categories:
Basic (BMP, Basic Multilingual Plane) code points: values from
0x0to0xFFFF, which can be represented by a single Char (16-bit value).Supplementary code points: values from
0x10000to0x10FFFF, which require a surrogate pair of two Char values.
This value class provides a type-safe representation of Unicode code points and operations for working with them, including conversion to/from characters and surrogate pairs, arithmetic operations, and range creation.
Creating CodePoint instances
Code points can be created in several ways:
val fromCode = CodePoint(0x1F600) // from integer code
val fromInt = 0x1F600.toCodePoint() // from Int using extension
val fromChar = 'a'.toCodePoint() // from Char
val emoji = CodePoint.fromSurrogatePair(high, low) // from surrogate pairConverting to characters
Use toSingleChar for basic code points to get a single Char.
Use toSurrogatePair for supplementary code points to get the surrogate pair representation.
Use toCharArray for both basic and supplementary code point to get an array of either one or two Char values.
Use toString to get a string representation of the code point consisting of either one or two Char values.
Arithmetic and ranges
CodePoint supports arithmetic operations and range creation:
val next = codePoint + 1
val distance = codePoint2 - codePoint1
val range = 'a'.toCodePoint()..'z'.toCodePoint()Since Kotlin
2.5Throws
if the provided code value is outside the valid range.
Samples
import kotlin.text.unicode.*
import kotlin.test.*
fun main() {
//sampleStart
val validCodePoint = CodePoint(0x1F60B) // 😋
println(validCodePoint) // 😋
// val invalidCodePoint = CodePoint(0x20FFFF) // will fail with IllegalArgumentException
//sampleEnd
}Constructors
Properties
Returns the Unicode general category of the Unicode character corresponding to this code point.
Returns the Unicode general category of the Unicode character corresponding to this code point.
Returns true if this is a supplementary code point that can be represented by a surrogate pair of two Char values.
Functions
Returns a progression from this value down to and including the specified to value with the step -1.
Returns true if the Unicode character corresponding to this code point is defined in Unicode.
Returns true if this character (Unicode code point) is defined in Unicode.
Returns true if the Unicode character corresponding to this code point is a digit.
Returns true if the Unicode character corresponding to this code point is a digit.
Returns true if the Unicode character corresponding to this code point is an ISO control character.
Returns true if the Unicode character corresponding to this code point is an ISO control character.
Returns true if the Unicode character corresponding to this code point is a letter.
Returns true if the Unicode character corresponding to this code point is a letter.
Returns true if the Unicode character corresponding to this code point is a letter or digit.
Returns true if the Unicode character corresponding to this code point is a letter or digit.
Returns true if the Unicode character corresponding to this code point is lower case.
Returns true if the Unicode character corresponding to this code point is lower case.
Returns true if the Unicode character corresponding to this code point is a title case letter.
Returns true if the Unicode character corresponding to this code point is a title case letter.
Returns true if the Unicode character corresponding to this code point is upper case.
Returns true if the Unicode character corresponding to this code point is upper case.
Determines whether the Unicode character corresponding to this code point is whitespace.
Determines whether the Unicode character corresponding to this code point is whitespace.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Converts this code point to lower case using Unicode mapping rules of the invariant locale.
Creates a range from this value to the specified other value.
Creates a range from this value up to but excluding the specified other value.
Converts this code point to title case using Unicode mapping rules of the invariant locale.
Converts this code point to title case using Unicode mapping rules of the invariant locale.
Converts this code point to title case using Unicode mapping rules of the invariant locale.
Converts this supplementary code point to a surrogate pair.
Converts this supplementary code point to a surrogate pair and applies the given action to its components.
Returns a range from this value up to but excluding the specified other value.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.
Converts this code point to upper case using Unicode mapping rules of the invariant locale.