#ifndef STRINGUTILITY_H #define STRINGUTILITY_H #include #include namespace std { template std::basic_string to_string(const std::basic_string_view &str) { return std::basic_string(str.begin(), str.end()); } } // namespace std namespace Amass { namespace StringUtility { template std::vector> split(const std::basic_string &string, const std::basic_string_view &delimiter) { std::vector> ret; if (delimiter.empty() || string.empty()) return ret; auto buf = string; size_t pos = std::string::npos; size_t delimiterLength = delimiter.length(); while (true) { pos = buf.find(delimiter); if (pos != std::basic_string::npos) { auto substr = buf.substr(0, pos); if (!substr.empty()) ret.push_back(substr); buf = buf.substr(pos + delimiterLength); } else { if (!buf.empty()) ret.push_back(buf); break; } } return ret; } inline std::vector split(const std::string &string, const std::string_view &delimiter) { return split(string, delimiter); } std::string &replace(std::string &string, const std::string &before, const std::string &after); template std::basic_string trimmed(const std::basic_string &string) { static const CharT *whitespace = std::is_same_v ? reinterpret_cast("\t\n\v\f\r ") : reinterpret_cast(L"\t\n\v\f\r "); auto begin = string.find_first_not_of(whitespace); if (begin == std::basic_string::npos) return std::basic_string(); auto end = string.find_last_not_of(whitespace); if (end == std::basic_string::npos) return std::basic_string(); return string.substr(begin, end - begin + 1); } bool equal(std::string_view lhs, std::string_view rhs, bool caseSensitivity = true); size_t utf8Length(const std::string &text); std::string_view utf8At(const std::string &text, size_t index); size_t utf8CharacterByteSize(const char *character); std::wstring stringToWString(const std::string &string); } // namespace StringUtility } // namespace Amass #endif // STRINGUTILITY_H