-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add proper support for unicode characters
- Loading branch information
1 parent
e62c586
commit 640f122
Showing
4 changed files
with
35 additions
and
4 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
21 changes: 21 additions & 0 deletions
21
...in/kotlin/io/github/optimumcode/json/schema/internal/factories/string/util/UnicodeUtil.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 @@ | ||
package io.github.optimumcode.json.schema.internal.factories.string.util | ||
|
||
internal fun CharSequence.codePointCount(): Int { | ||
val endIndex = length | ||
var index = 0 | ||
var count = 0 | ||
while (index < endIndex) { | ||
val firstChar = this[index] | ||
index++ | ||
if (firstChar.isHighSurrogate() && index < endIndex) { | ||
val nextChar = this[index] | ||
if (nextChar.isLowSurrogate()) { | ||
index++ | ||
} | ||
} | ||
|
||
count++ | ||
} | ||
|
||
return count | ||
} |
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