From 9e4419826b3e23c63567591701a2834a837da98e Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 17 Oct 2025 09:46:56 +0800 Subject: Toml remove String. --- include/cru/base/StringUtil.h | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) (limited to 'include/cru/base') diff --git a/include/cru/base/StringUtil.h b/include/cru/base/StringUtil.h index f2373444..d79c0c23 100644 --- a/include/cru/base/StringUtil.h +++ b/include/cru/base/StringUtil.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -16,7 +17,7 @@ std::weak_ordering CaseInsensitiveCompare(std::string_view left, std::string TrimBegin(std::string_view str); std::string TrimEnd(std::string_view str); std::string Trim(std::string_view str); -} // namespace string +bool IsSpace(std::string_view str); namespace details { struct SplitOptionsTag {}; @@ -24,43 +25,12 @@ struct SplitOptionsTag {}; using SplitOption = Bitmask; struct SplitOptions { static constexpr SplitOption RemoveEmpty = SplitOption::FromOffset(1); + static constexpr SplitOption RemoveSpace = SplitOption::FromOffset(2); }; -template -std::vector Split(const TString& str, const TString& sep, - SplitOption options = {}) { - using size_type = typename TString::size_type; - - if (sep.empty()) throw std::invalid_argument("Sep can't be empty."); - if (str.empty()) return {}; - - size_type current_pos = 0; - std::vector result; - - while (current_pos != TString::npos) { - if (current_pos == str.size()) { - if (!options.Has(SplitOptions::RemoveEmpty)) { - result.push_back({}); - } - break; - } - - auto next_pos = str.find(sep, current_pos); - auto sub = str.substr(current_pos, next_pos - current_pos); - if (!(options.Has(SplitOptions::RemoveEmpty) && sub.empty())) { - result.push_back(sub); - } - current_pos = - next_pos == TString::npos ? TString::npos : next_pos + sep.size(); - } - - return result; -} - -inline std::vector Split(const char* str, const std::string& sep, - SplitOption options = {}) { - return Split(std::string(str), sep, options); -} +std::vector Split(std::string_view str, std::string_view sep, + SplitOption options = {}); +} // namespace string using CodePoint = std::int32_t; constexpr CodePoint k_invalid_code_point = -1; -- cgit v1.2.3