Skip to content

Commit 2c72389

Browse files
committed
Switch StringBuilder extension functions to Appendable extension functions
1 parent 8fa6142 commit 2c72389

File tree

4 files changed

+20
-42
lines changed

4 files changed

+20
-42
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package de.cketti.codepoints.deluxe
22

3+
import de.cketti.codepoints.CodePoints
34
import de.cketti.codepoints.appendCodePoint as intAppendCodePoint
45

56
/**
6-
* Appends the string representation of the [codePoint] argument to this sequence.
7+
* Appends the string representation of the [codePoint] argument to this Appendable and returns this instance.
78
*
8-
* The argument is appended to the contents of this sequence.
9-
* The length of this sequence increases by [CodePoint.charCount].
9+
* To append the codepoint, [Appendable.append(Char)][Appendable.append] is called [CodePoints.charCount] times.
1010
*
1111
* 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.
12+
* [CodePoints.toChars] and the characters in that array were then appended to this Appendable.
1313
*/
14-
fun StringBuilder.appendCodePoint(codePoint: CodePoint): StringBuilder = intAppendCodePoint(codePoint.value)
14+
fun <T : Appendable> T.appendCodePoint(codePoint: CodePoint): T = intAppendCodePoint(codePoint.value)

kotlin-codepoints/src/commonImplementation/kotlin/StringBuilderExtensions.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
@file:Suppress(
2-
"EXTENSION_SHADOWED_BY_MEMBER", // Kotlin/JVM aliases StringBuilder to j.l.StringBuilder.
3-
"KotlinRedundantDiagnosticSuppress", // Above suppression only needed for JVM.
4-
)
5-
61
package de.cketti.codepoints
72

3+
import de.cketti.codepoints.CodePoints.highSurrogate
4+
import de.cketti.codepoints.CodePoints.isBmpCodePoint
5+
import de.cketti.codepoints.CodePoints.lowSurrogate
6+
87
/**
9-
* Appends the string representation of the [codePoint] argument to this sequence.
8+
* Appends the string representation of the [codePoint] argument to this Appendable and returns this instance.
109
*
11-
* The argument is appended to the contents of this sequence.
12-
* The length of this sequence increases by [CodePoints.charCount].
10+
* To append the codepoint, [Appendable.append(Char)][Appendable.append] is called [CodePoints.charCount] times.
1311
*
1412
* The overall effect is exactly as if the argument were converted to a char array by the function
15-
* [CodePoints.toChars] and the characters in that array were then appended to this sequence.
13+
* [CodePoints.toChars] and the characters in that array were then appended to this Appendable.
1614
*/
17-
expect fun StringBuilder.appendCodePoint(codePoint: Int): StringBuilder
15+
fun <T : Appendable> T.appendCodePoint(codePoint: Int): T = apply {
16+
if (isBmpCodePoint(codePoint)) {
17+
append(codePoint.toChar())
18+
} else {
19+
append(highSurrogate(codePoint))
20+
append(lowSurrogate(codePoint))
21+
}
22+
}

kotlin-codepoints/src/jvmMain/kotlin/StringBuilderExtensions.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)