File tree 4 files changed +34
-3
lines changed
kotlin-codepoints-deluxe/src
4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
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
+
3
10
## [ 0.8.0] - 2024-06-09
4
11
### Changed
5
12
- 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.
64
64
val text = " 🦕&🦖"
65
65
66
66
for (codePoint in text.codePointSequence()) {
67
- print (" code point: $codePoint , char count: ${codePoint.charCount} " )
67
+ print (" code point: ${ codePoint.toUnicodeNotation()} , char count: ${codePoint.charCount} " )
68
68
69
69
if (codePoint.isBasic) {
70
70
println (" - boring!" )
Original file line number Diff line number Diff line change @@ -102,14 +102,23 @@ value class CodePoint internal constructor(val value: Int) {
102
102
}
103
103
104
104
/* *
105
- * Returns a string representation of this code point.
105
+ * Returns the standard Unicode notation of this code point.
106
106
*
107
107
* "U+" followed by the code point value in hexadecimal (using upper case letters), which is prepended with leading
108
108
* zeros to a minimum of four digits.
109
109
*/
110
- override fun toString (): String {
110
+ fun toUnicodeNotation (): String {
111
111
return " U+${value.toString(16 ).uppercase().padStart(4 , ' 0' )} "
112
112
}
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
+ }
113
122
}
114
123
115
124
/* *
Original file line number Diff line number Diff line change @@ -165,4 +165,19 @@ class CodePointTest {
165
165
}
166
166
assertContentEquals(charArrayOf(' z' , ' z' ), chars)
167
167
}
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
+ }
168
183
}
You can’t perform that action at this time.
0 commit comments