Skip to content

Commit bba16de

Browse files
committed
Add StringBuilder.appendCodePoint() to kotlin-codepoints-deluxe
1 parent 9153df5 commit bba16de

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package de.cketti.codepoints.deluxe
2+
3+
import de.cketti.codepoints.appendCodePoint as intAppendCodePoint
4+
5+
/**
6+
* Appends the string representation of the [codePoint] argument to this sequence.
7+
*
8+
* The argument is appended to the contents of this sequence.
9+
* The length of this sequence increases by [CodePoint.charCount].
10+
*
11+
* The overall effect is exactly as if the argument were converted to a char array by the function
12+
* [CodePoint.toChars] and the characters in that array were then appended to this sequence.
13+
*/
14+
fun StringBuilder.appendCodePoint(codePoint: CodePoint): StringBuilder = intAppendCodePoint(codePoint.value)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package de.cketti.codepoints.deluxe
2+
3+
import kotlin.test.assertEquals
4+
import kotlin.test.Test
5+
6+
class StringBuilderExtensionsTest {
7+
@Test
8+
fun appendCodePoint() {
9+
val actual = buildString {
10+
appendCodePoint('a'.toCodePoint())
11+
append('b')
12+
appendCodePoint('\uFFFF'.toCodePoint())
13+
append('c')
14+
appendCodePoint("\uD83E\uDD95".codePointAt(0))
15+
}
16+
17+
assertEquals("ab\uFFFFc\uD83E\uDD95", actual)
18+
}
19+
}

0 commit comments

Comments
 (0)