From 1f28ff5f182050028e45dc230a29165bf78bfb9f Mon Sep 17 00:00:00 2001 From: gibbed Date: Mon, 20 Apr 2020 00:31:40 -0500 Subject: [PATCH] [Base] Add opt arg to allow empty parts in split. [Base] Add optional argument to allow empty parts in utf8::split. --- src/xenia/base/utf8.cc | 7 +++++-- src/xenia/base/utf8.h | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/xenia/base/utf8.cc b/src/xenia/base/utf8.cc index 22d78f9cf..88abe3b6c 100644 --- a/src/xenia/base/utf8.cc +++ b/src/xenia/base/utf8.cc @@ -159,7 +159,8 @@ inline utf8_citer find_needle_case(utf8_citer haystack_it, } std::vector split(const std::string_view haystack, - const std::string_view needles) { + const std::string_view needles, + bool remove_empty) { std::vector result; auto [haystack_begin, haystack_end] = make_citer(haystack); @@ -177,6 +178,8 @@ std::vector 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 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, diff --git a/src/xenia/base/utf8.h b/src/xenia/base/utf8.h index 73094ccbf..bfdf99b87 100644 --- a/src/xenia/base/utf8.h +++ b/src/xenia/base/utf8.h @@ -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 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);