[Glacier] Add a StringView class and StrSplit method.

This commit is contained in:
Drew Galbraith 2023-11-02 20:23:28 -07:00
parent b6c220a350
commit a2e80952c8
8 changed files with 159 additions and 4 deletions

View file

@ -0,0 +1,17 @@
#include "glacier/string/str_split.h"
namespace glcr {
Vector<StringView> StrSplit(const StringView& str, char delimiter) {
Vector<StringView> strings;
uint64_t cur_pos = 0;
uint64_t next_pos = 0;
while ((next_pos = str.find(delimiter, cur_pos)) != str.npos) {
strings.PushBack(str.substr(cur_pos, next_pos - cur_pos));
cur_pos = next_pos + 1;
}
strings.PushBack(str.substr(cur_pos, str.size() - cur_pos));
return strings;
}
} // namespace glcr