diff options
| author | gingerBill <bill@gingerbill.org> | 2019-10-26 11:50:01 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-10-26 11:50:01 +0100 |
| commit | 1da0668653a4bc800a56629664f4e716c4560fa3 (patch) | |
| tree | 096d2566d42e2d6797043b8339d513ae22a7cc95 | |
| parent | c60fb10a6a0b668e9dab7e4cb899664f5e32419e (diff) | |
Add `utf8.rune_index`
| -rw-r--r-- | core/unicode/utf8/utf8.odin | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/core/unicode/utf8/utf8.odin b/core/unicode/utf8/utf8.odin index 33cb48e1c..4a4e2f459 100644 --- a/core/unicode/utf8/utf8.odin +++ b/core/unicode/utf8/utf8.odin @@ -167,9 +167,20 @@ decode_last_rune :: proc(s: []u8) -> (rune, int) { return r, size; } +rune_index :: proc(s: string, index: int) -> (r: rune = RUNE_ERROR, ok: bool = false) { + if index < 0 { + return; + } - - + i := 0; + for c in s { + if i == index { + return r, true; + } + i += 1; + } + return; +} valid_rune :: proc(r: rune) -> bool { if r < 0 { |