aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2024-10-23 15:25:21 +0100
committerGitHub <noreply@github.com>2024-10-23 15:25:21 +0100
commitf047f804f67bd57713d058a0df6d83c49e0f3848 (patch)
tree74631d7579ae51d1de15921ad81a672847d302ad
parent33cc6713028b1bebfb3b023faad88795761a6276 (diff)
parent66c53a11742eb974607ec20a9c293030cbf3c86e (diff)
Merge pull request #4402 from Lperlind/utf16_rune_count
core/unicode/utf16: add rune_count proc
-rw-r--r--core/unicode/utf16/utf16.odin14
1 files changed, 13 insertions, 1 deletions
diff --git a/core/unicode/utf16/utf16.odin b/core/unicode/utf16/utf16.odin
index 6bdd6558a..e2bcf7f68 100644
--- a/core/unicode/utf16/utf16.odin
+++ b/core/unicode/utf16/utf16.odin
@@ -106,6 +106,18 @@ decode :: proc(d: []rune, s: []u16) -> (n: int) {
return
}
+rune_count :: proc(s: []u16) -> (n: int) {
+ for i := 0; i < len(s); i += 1 {
+ c := s[i]
+ if _surr1 <= c && c < _surr2 && i+1 < len(s) &&
+ _surr2 <= s[i+1] && s[i+1] < _surr3 {
+ i += 1
+ }
+ n += 1
+ }
+ return
+}
+
decode_to_utf8 :: proc(d: []byte, s: []u16) -> (n: int) {
for i := 0; i < len(s); i += 1 {
@@ -127,4 +139,4 @@ decode_to_utf8 :: proc(d: []byte, s: []u16) -> (n: int) {
n += copy(d[n:], b[:w])
}
return
-} \ No newline at end of file
+}