diff options
| author | Lucas Perlind <perlindluca@gmail.com> | 2022-03-21 21:17:49 +1100 |
|---|---|---|
| committer | Lucas Perlind <perlindluca@gmail.com> | 2022-03-21 21:39:30 +1100 |
| commit | 6d354524e28ffe69f0ce769a4d031035784d8b47 (patch) | |
| tree | b756ffbb89ddd6151f1a616b26e1fa4236069e21 /core/strings | |
| parent | ae6441182de5185812b9e5558b08ccaa3a877cdc (diff) | |
* Add split_by_byte_iterator. It functions exactly like split_iterator but takes in a byte seperator rather than a string seperator.
The intention is to provide a faster split parsing if the seperator is known to be byte size.
Diffstat (limited to 'core/strings')
| -rw-r--r-- | core/strings/strings.odin | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/strings/strings.odin b/core/strings/strings.odin index 670da166b..fe25ad3bf 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -339,6 +339,25 @@ _split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string, return } +@private +_split_by_byte_iterator :: proc(s: ^string, sep: u8) -> (res: string, ok: bool) { + m := index_byte(s^, sep) + if m < 0 { + // not found + res = s[:] + ok = res != "" + s^ = {} + } else { + res = s[:m] + ok = true + s^ = s[m+1:] + } + return +} + +split_by_byte_iterator :: proc(s: ^string, sep: u8) -> (string, bool) { + return _split_by_byte_iterator(s, sep) +} split_iterator :: proc(s: ^string, sep: string) -> (string, bool) { return _split_iterator(s, sep, 0) |