Skip to content

Commit

Permalink
Merge pull request #4402 from Lperlind/utf16_rune_count
Browse files Browse the repository at this point in the history
core/unicode/utf16: add rune_count proc
  • Loading branch information
gingerBill authored Oct 23, 2024
2 parents 33cc671 + 66c53a1 commit f047f80
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/unicode/utf16/utf16.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -127,4 +139,4 @@ decode_to_utf8 :: proc(d: []byte, s: []u16) -> (n: int) {
n += copy(d[n:], b[:w])
}
return
}
}

0 comments on commit f047f80

Please sign in to comment.