diff --git a/common/StringUtil.cpp b/common/StringUtil.cpp index fab6cdf9a5..0fa7409578 100644 --- a/common/StringUtil.cpp +++ b/common/StringUtil.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef _WIN32 #include "RedtapeWindows.h" @@ -206,6 +207,35 @@ namespace StringUtil return ss.str(); } + std::string toLower(const std::string_view& input) + { + std::string newStr; + std::transform(input.begin(), input.end(), std::back_inserter(newStr), + [](unsigned char c) { return std::tolower(c); }); + return newStr; + } + + bool compareNoCase(const std::string_view& str1, const std::string_view& str2) + { + if (str1.length() != str2.length()) + { + return false; + } + return Strncasecmp(str1.data(), str2.data(), str1.length()) == 0; + } + + std::vector splitOnNewLine(const std::string& str) + { + std::vector lines; + std::istringstream stream(str); + std::string line; + while (std::getline(stream, line)) + { + lines.push_back(line); + } + return lines; + } + #ifdef _WIN32 std::wstring UTF8StringToWideString(const std::string_view& str) diff --git a/common/StringUtil.h b/common/StringUtil.h index 46a91f0a4d..d7a31056a2 100644 --- a/common/StringUtil.h +++ b/common/StringUtil.h @@ -184,6 +184,10 @@ namespace StringUtil return 0; } + std::string toLower(const std::string_view& str); + bool compareNoCase(const std::string_view& str1, const std::string_view& str2); + std::vector splitOnNewLine(const std::string& str); + /// Converts a wxString to a UTF-8 std::string. static std::string wxStringToUTF8String(const wxString& str) {