File tree Expand file tree Collapse file tree 4 files changed +34
-3
lines changed
kotlin-codepoints-deluxe/src Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 11# Changelog
22
3+ ## [ Unreleased]
4+ ### Changed
5+ - ` CodePoint.toString() ` now returns the string representation of a code point.
6+
7+ ### Added
8+ - ` CodePoint.toUnicodeNotation() ` returns the standard Unicode notation of a code point, e.g. ` U+1F4E7 ` .
9+
310## [ 0.8.0] - 2024-06-09
411### Changed
512- Updated to Kotlin 2.0.0
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ to get and idea of what's available.
6464val text = " 🦕&🦖"
6565
6666for (codePoint in text.codePointSequence()) {
67- print (" code point: $codePoint , char count: ${codePoint.charCount} " )
67+ print (" code point: ${ codePoint.toUnicodeNotation()} , char count: ${codePoint.charCount} " )
6868
6969 if (codePoint.isBasic) {
7070 println (" - boring!" )
Original file line number Diff line number Diff line change @@ -102,14 +102,23 @@ value class CodePoint internal constructor(val value: Int) {
102102 }
103103
104104 /* *
105- * Returns a string representation of this code point.
105+ * Returns the standard Unicode notation of this code point.
106106 *
107107 * "U+" followed by the code point value in hexadecimal (using upper case letters), which is prepended with leading
108108 * zeros to a minimum of four digits.
109109 */
110- override fun toString (): String {
110+ fun toUnicodeNotation (): String {
111111 return " U+${value.toString(16 ).uppercase().padStart(4 , ' 0' )} "
112112 }
113+
114+ /* *
115+ * Returns the string representation of this code point.
116+ *
117+ * The returned string consists of the sequence of characters returned by [toChars].
118+ */
119+ override fun toString (): String {
120+ return toChars().concatToString()
121+ }
113122}
114123
115124/* *
Original file line number Diff line number Diff line change @@ -165,4 +165,19 @@ class CodePointTest {
165165 }
166166 assertContentEquals(charArrayOf(' z' , ' z' ), chars)
167167 }
168+
169+ @Test
170+ fun toUnicodeNotation () {
171+ assertEquals(" U+0000" , 0 .toCodePoint().toUnicodeNotation())
172+ assertEquals(" U+0061" , ' a' .toCodePoint().toUnicodeNotation())
173+ assertEquals(" U+0FFF" , 0xFFF .toCodePoint().toUnicodeNotation())
174+ assertEquals(" U+FFFF" , 0xFFFF .toCodePoint().toUnicodeNotation())
175+ assertEquals(" U+1F995" , 0x1F995 .toCodePoint().toUnicodeNotation())
176+ }
177+
178+ @Test
179+ fun toString_test () {
180+ assertEquals(" a" , ' a' .toCodePoint().toString())
181+ assertEquals(" \uD83E\uDD95 " , 0x1F995 .toCodePoint().toString())
182+ }
168183}
You can’t perform that action at this time.
0 commit comments