[Glacier] Add a StringView class and StrSplit method.
This commit is contained in:
parent
b6c220a350
commit
a2e80952c8
8 changed files with 159 additions and 4 deletions
17
lib/glacier/string/str_split.cpp
Normal file
17
lib/glacier/string/str_split.cpp
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue