Skip to content

Commit

Permalink
Switch StringBuilder extension functions to Appendable extension …
Browse files Browse the repository at this point in the history
…functions
  • Loading branch information
cketti committed Feb 25, 2023
1 parent 8fa6142 commit 2c72389
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package de.cketti.codepoints.deluxe

import de.cketti.codepoints.CodePoints
import de.cketti.codepoints.appendCodePoint as intAppendCodePoint

/**
* Appends the string representation of the [codePoint] argument to this sequence.
* Appends the string representation of the [codePoint] argument to this Appendable and returns this instance.
*
* The argument is appended to the contents of this sequence.
* The length of this sequence increases by [CodePoint.charCount].
* To append the codepoint, [Appendable.append(Char)][Appendable.append] is called [CodePoints.charCount] times.
*
* The overall effect is exactly as if the argument were converted to a char array by the function
* [CodePoint.toChars] and the characters in that array were then appended to this sequence.
* [CodePoints.toChars] and the characters in that array were then appended to this Appendable.
*/
fun StringBuilder.appendCodePoint(codePoint: CodePoint): StringBuilder = intAppendCodePoint(codePoint.value)
fun <T : Appendable> T.appendCodePoint(codePoint: CodePoint): T = intAppendCodePoint(codePoint.value)

This file was deleted.

25 changes: 15 additions & 10 deletions kotlin-codepoints/src/commonMain/kotlin/StringBuilderExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
@file:Suppress(
"EXTENSION_SHADOWED_BY_MEMBER", // Kotlin/JVM aliases StringBuilder to j.l.StringBuilder.
"KotlinRedundantDiagnosticSuppress", // Above suppression only needed for JVM.
)

package de.cketti.codepoints

import de.cketti.codepoints.CodePoints.highSurrogate
import de.cketti.codepoints.CodePoints.isBmpCodePoint
import de.cketti.codepoints.CodePoints.lowSurrogate

/**
* Appends the string representation of the [codePoint] argument to this sequence.
* Appends the string representation of the [codePoint] argument to this Appendable and returns this instance.
*
* The argument is appended to the contents of this sequence.
* The length of this sequence increases by [CodePoints.charCount].
* To append the codepoint, [Appendable.append(Char)][Appendable.append] is called [CodePoints.charCount] times.
*
* The overall effect is exactly as if the argument were converted to a char array by the function
* [CodePoints.toChars] and the characters in that array were then appended to this sequence.
* [CodePoints.toChars] and the characters in that array were then appended to this Appendable.
*/
expect fun StringBuilder.appendCodePoint(codePoint: Int): StringBuilder
fun <T : Appendable> T.appendCodePoint(codePoint: Int): T = apply {
if (isBmpCodePoint(codePoint)) {
append(codePoint.toChar())
} else {
append(highSurrogate(codePoint))
append(lowSurrogate(codePoint))
}
}
12 changes: 0 additions & 12 deletions kotlin-codepoints/src/jvmMain/kotlin/StringBuilderExtensions.kt

This file was deleted.

0 comments on commit 2c72389

Please sign in to comment.