aboutsummaryrefslogtreecommitdiff
path: root/core/unicode
diff options
context:
space:
mode:
Diffstat (limited to 'core/unicode')
-rw-r--r--core/unicode/utf16/utf16.odin32
1 files changed, 31 insertions, 1 deletions
diff --git a/core/unicode/utf16/utf16.odin b/core/unicode/utf16/utf16.odin
index 9a8cfe438..d3f98584b 100644
--- a/core/unicode/utf16/utf16.odin
+++ b/core/unicode/utf16/utf16.odin
@@ -126,7 +126,37 @@ decode_rune_in_string :: proc(s: string16) -> (r: rune, width: int) {
return
}
-rune_count :: proc(s: []u16) -> (n: int) {
+string_to_runes :: proc "odin" (s: string16, allocator := context.allocator) -> (runes: []rune) {
+ n := rune_count(s)
+
+ runes = make([]rune, n, allocator)
+ i := 0
+ for r in s {
+ runes[i] = r
+ i += 1
+ }
+ return
+}
+
+
+rune_count :: proc{
+ rune_count_in_string,
+ rune_count_in_slice,
+}
+rune_count_in_string :: proc(s: string16) -> (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
+}
+
+
+rune_count_in_slice :: 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) &&