diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-08-02 12:20:35 +0100 |
|---|---|---|
| committer | gingerBill <gingerBill@users.noreply.github.com> | 2025-08-02 12:20:35 +0100 |
| commit | bb4bc316a4bd86774953f1e8fcefffb5ed8bbf37 (patch) | |
| tree | bd48bf739dd69c0bc6578fb2a69cc5823ddee6f8 /core/unicode | |
| parent | ae02d3d02d2eb5132fa7c6573ed7db20d7e18f3e (diff) | |
`for in string16`; Support `string16` across core
Diffstat (limited to 'core/unicode')
| -rw-r--r-- | core/unicode/utf16/utf16.odin | 32 |
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) && |