-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch
StringBuilder
extension functions to Appendable
extension …
…functions
- Loading branch information
Showing
4 changed files
with
20 additions
and
42 deletions.
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
kotlin-codepoints-deluxe/src/commonMain/kotlin/StringBuilderExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
15 changes: 0 additions & 15 deletions
15
kotlin-codepoints/src/commonImplementation/kotlin/StringBuilderExtensions.kt
This file was deleted.
Oops, something went wrong.
25 changes: 15 additions & 10 deletions
25
kotlin-codepoints/src/commonMain/kotlin/StringBuilderExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
kotlin-codepoints/src/jvmMain/kotlin/StringBuilderExtensions.kt
This file was deleted.
Oops, something went wrong.