-
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.
- Move common implementation to its own package - Remove useless objects in common implementation - Remove inline keyword from most methods
- Loading branch information
Showing
7 changed files
with
207 additions
and
193 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
59 changes: 59 additions & 0 deletions
59
src/commonImplementation/kotlin/internal/CommonCodePoints.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,59 @@ | ||
package de.cketti.codepoints.internal | ||
|
||
private const val MIN_SUPPLEMENTARY_CODE_POINT = 0x10000 | ||
private const val MAX_CODE_POINT = 0x10FFFF | ||
|
||
private const val MIN_HIGH_SURROGATE = 0xD800 | ||
private const val MAX_HIGH_SURROGATE = 0xDBFF | ||
private const val MIN_LOW_SURROGATE = 0xDC00 | ||
private const val MAX_LOW_SURROGATE = 0xDFFF | ||
|
||
private const val SURROGATE_DECODE_OFFSET = | ||
MIN_SUPPLEMENTARY_CODE_POINT - (MIN_HIGH_SURROGATE shl 10) - MIN_LOW_SURROGATE | ||
|
||
private const val HIGH_SURROGATE_ENCODE_OFFSET = | ||
(MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT ushr 10)) | ||
|
||
internal fun isValidCodePoint(codePoint: Int): Boolean { | ||
return codePoint in 0..MAX_CODE_POINT | ||
} | ||
|
||
internal fun isBmpCodePoint(codePoint: Int): Boolean { | ||
return codePoint ushr 16 == 0 | ||
} | ||
|
||
internal fun isSupplementaryCodePoint(codePoint: Int): Boolean { | ||
return codePoint in MIN_SUPPLEMENTARY_CODE_POINT..MAX_CODE_POINT | ||
} | ||
|
||
internal fun charCount(codePoint: Int): Int { | ||
return if (codePoint < MIN_SUPPLEMENTARY_CODE_POINT) 1 else 2 | ||
} | ||
|
||
internal fun isSurrogate(char: Char): Boolean { | ||
return char.code in MIN_HIGH_SURROGATE..MAX_LOW_SURROGATE | ||
} | ||
|
||
internal fun isHighSurrogate(char: Char): Boolean { | ||
return char.code in MIN_HIGH_SURROGATE..MAX_HIGH_SURROGATE | ||
} | ||
|
||
internal fun isLowSurrogate(char: Char): Boolean { | ||
return char.code in MIN_LOW_SURROGATE..MAX_LOW_SURROGATE | ||
} | ||
|
||
internal fun isSurrogatePair(highSurrogate: Char, lowSurrogate: Char): Boolean { | ||
return isHighSurrogate(highSurrogate) && isLowSurrogate(lowSurrogate) | ||
} | ||
|
||
internal fun highSurrogate(codePoint: Int): Char { | ||
return ((codePoint ushr 10) + HIGH_SURROGATE_ENCODE_OFFSET).toChar() | ||
} | ||
|
||
internal fun lowSurrogate(codePoint: Int): Char { | ||
return ((codePoint and 0x3FF) + MIN_LOW_SURROGATE).toChar() | ||
} | ||
|
||
internal fun toCodePoint(highSurrogate: Char, lowSurrogate: Char): Int { | ||
return (highSurrogate.code shl 10) + lowSurrogate.code + SURROGATE_DECODE_OFFSET | ||
} |
Oops, something went wrong.