[Base] Add opt arg to allow empty parts in split.

[Base] Add optional argument to allow empty parts in utf8::split.
This commit is contained in:
gibbed 2020-04-20 00:31:40 -05:00 committed by Rick Gibbed
parent 817d87a0a7
commit 1f28ff5f18
2 changed files with 7 additions and 3 deletions

View File

@ -159,7 +159,8 @@ inline utf8_citer find_needle_case(utf8_citer haystack_it,
}
std::vector<std::string_view> split(const std::string_view haystack,
const std::string_view needles) {
const std::string_view needles,
bool remove_empty) {
std::vector<std::string_view> result;
auto [haystack_begin, haystack_end] = make_citer(haystack);
@ -177,6 +178,8 @@ std::vector<std::string_view> split(const std::string_view haystack,
auto offset = byte_length(haystack_begin, last);
auto length = byte_length(haystack_begin, it) - offset;
result.push_back(haystack.substr(offset, length));
} else if (!remove_empty) {
result.push_back("");
}
++it;
@ -478,7 +481,7 @@ bool ends_with_case(const std::string_view haystack,
}
std::vector<std::string_view> split_path(const std::string_view path) {
return split(path, u8"\\/");
return split(path, u8"\\/", true);
}
std::string join_paths(const std::string_view left_path,

View File

@ -27,7 +27,8 @@ size_t hash_fnv1a_case(const std::string_view view);
// Splits the given string on any delimiters and returns all parts.
std::vector<std::string_view> split(const std::string_view path,
const std::string_view delimiters);
const std::string_view delimiters,
bool remove_empty = false);
bool equal_z(const std::string_view left, const std::string_view right);