diff options
| author | FourteenBrush <naessensarthur2@protonmail.com> | 2024-01-25 10:15:25 +0100 |
|---|---|---|
| committer | FourteenBrush <naessensarthur2@protonmail.com> | 2024-01-25 10:15:25 +0100 |
| commit | 967ccfc7ccc0f76c653ff4bb625bac60e89a7904 (patch) | |
| tree | f989a0f99337c7a0c93ee84249d73ec0c33e306d /src/string.cpp | |
| parent | 712ae1c5ac73493498aa8e5076d91a6558337117 (diff) | |
| parent | 9cfd4a953e2a7d19237891993b643b2d1477f8b3 (diff) | |
Merge branch 'master' of https://github.com/FourteenBrush/Odin
Diffstat (limited to 'src/string.cpp')
| -rw-r--r-- | src/string.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/string.cpp b/src/string.cpp index 6eac4f53b..9fb933b1b 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -10,6 +10,10 @@ struct String { return text[i]; } }; +struct String_Iterator { + String const &str; + isize pos; +}; // NOTE(bill): used for printf style arguments #define LIT(x) ((int)(x).len), (x).text #if defined(GB_COMPILER_MSVC) && _MSC_VER < 1700 @@ -201,11 +205,31 @@ gb_internal gb_inline String string_trim_starts_with(String const &s, String con } +gb_internal String string_split_iterator(String_Iterator *it, const char sep) { + isize start = it->pos; + isize end = it->str.len; + + if (start == end) { + return str_lit(""); + } + + isize i = start; + for (; i < it->str.len; i++) { + if (it->str[i] == sep) { + String res = substring(it->str, start, i); + it->pos += res.len + 1; + return res; + } + } + it->pos = end; + return substring(it->str, start, end); +} + gb_internal gb_inline isize string_extension_position(String const &str) { isize dot_pos = -1; isize i = str.len; while (i --> 0) { - if (str[i] == GB_PATH_SEPARATOR) + if (str[i] == '\\' || str[i] == '/') break; if (str[i] == '.') { dot_pos = i; |