-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support unicode symbols in strings (#122)
Fixes #72
- Loading branch information
Valentin Rocher
authored
Mar 11, 2022
1 parent
baed32d
commit 4d2fb18
Showing
8 changed files
with
169 additions
and
24 deletions.
There are no files selected for viewing
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
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
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
21 changes: 21 additions & 0 deletions
21
ktoml-core/src/jsMain/kotlin/com/akuleshov7/ktoml/utils/UtilsJs.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Specific implementation for utilities | ||
*/ | ||
|
||
package com.akuleshov7.ktoml.utils | ||
|
||
@Suppress("LONG_NUMERICAL_VALUES_SEPARATED") | ||
private const val MAX_CODE_POINT = 0x10FFFFf | ||
private const val MIN_SUPPLEMENTARY_CODE_POINT: Int = 0x10000 | ||
private const val MIN_LOW_SURROGATE: Int = '\uDC00'.code | ||
private const val MIN_HIGH_SURROGATE: Int = '\uD800'.code | ||
|
||
@Suppress("MAGIC_NUMBER") | ||
internal actual fun StringBuilder.appendCodePointCompat(codePoint: Int): StringBuilder = when (codePoint) { | ||
in 0 until MIN_SUPPLEMENTARY_CODE_POINT -> append(codePoint.toChar()) | ||
in MIN_SUPPLEMENTARY_CODE_POINT..MAX_CODE_POINT -> { | ||
append(Char.MIN_HIGH_SURROGATE + ((codePoint - 0x10000) shr 10)) | ||
append(Char.MIN_LOW_SURROGATE + (codePoint and 0x3ff)) | ||
} | ||
else -> throw IllegalArgumentException() | ||
} |
7 changes: 7 additions & 0 deletions
7
ktoml-core/src/jvmMain/kotlin/com/akuleshov7/ktoml/utils/UtilsJvm.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Specific implementation for utilities | ||
*/ | ||
|
||
package com.akuleshov7.ktoml.utils | ||
|
||
internal actual fun StringBuilder.appendCodePointCompat(codePoint: Int): StringBuilder = appendCodePoint(codePoint) |
15 changes: 15 additions & 0 deletions
15
ktoml-core/src/linuxX64Main/kotlin/com/akuleshov7/ktoml/utils/UtilsLinux.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Specific implementation for utilities | ||
*/ | ||
|
||
package com.akuleshov7.ktoml.utils | ||
|
||
@Suppress("MAGIC_NUMBER") | ||
internal actual fun StringBuilder.appendCodePointCompat(codePoint: Int): StringBuilder = when (codePoint) { | ||
in 0 until Char.MIN_SUPPLEMENTARY_CODE_POINT -> append(codePoint.toChar()) | ||
in Char.MIN_SUPPLEMENTARY_CODE_POINT..Char.MAX_CODE_POINT -> { | ||
append(Char.MIN_HIGH_SURROGATE + ((codePoint - 0x10000) shr 10)) | ||
append(Char.MIN_LOW_SURROGATE + (codePoint and 0x3ff)) | ||
} | ||
else -> throw IllegalArgumentException() | ||
} |
15 changes: 15 additions & 0 deletions
15
ktoml-core/src/macosX64Main/kotlin/com/akuleshov7/ktoml/utils/UtilsMac.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Specific implementation for utilities | ||
*/ | ||
|
||
package com.akuleshov7.ktoml.utils | ||
|
||
@Suppress("MAGIC_NUMBER") | ||
internal actual fun StringBuilder.appendCodePointCompat(codePoint: Int): StringBuilder = when (codePoint) { | ||
in 0 until Char.MIN_SUPPLEMENTARY_CODE_POINT -> append(codePoint.toChar()) | ||
in Char.MIN_SUPPLEMENTARY_CODE_POINT..Char.MAX_CODE_POINT -> { | ||
append(Char.MIN_HIGH_SURROGATE + ((codePoint - 0x10000) shr 10)) | ||
append(Char.MIN_LOW_SURROGATE + (codePoint and 0x3ff)) | ||
} | ||
else -> throw IllegalArgumentException() | ||
} |
15 changes: 15 additions & 0 deletions
15
ktoml-core/src/mingwX64Main/kotlin/com/akuleshov7/ktoml/utils/UtilsWin.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Specific implementation for utilities | ||
*/ | ||
|
||
package com.akuleshov7.ktoml.utils | ||
|
||
@Suppress("MAGIC_NUMBER") | ||
internal actual fun StringBuilder.appendCodePointCompat(codePoint: Int): StringBuilder = when (codePoint) { | ||
in 0 until Char.MIN_SUPPLEMENTARY_CODE_POINT -> append(codePoint.toChar()) | ||
in Char.MIN_SUPPLEMENTARY_CODE_POINT..Char.MAX_CODE_POINT -> { | ||
append(Char.MIN_HIGH_SURROGATE + ((codePoint - 0x10000) shr 10)) | ||
append(Char.MIN_LOW_SURROGATE + (codePoint and 0x3ff)) | ||
} | ||
else -> throw IllegalArgumentException() | ||
} |