common: pull our string functions into common

This commit is contained in:
Tyler Wilding 2021-12-23 21:59:17 -05:00 committed by refractionpcsx2
parent be952e40ba
commit e313eadcd2
2 changed files with 34 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include <codecvt>
#include <cstdio>
#include <sstream>
#include <algorithm>
#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<std::string> splitOnNewLine(const std::string& str)
{
std::vector<std::string> 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)

View File

@ -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<std::string> splitOnNewLine(const std::string& str);
/// Converts a wxString to a UTF-8 std::string.
static std::string wxStringToUTF8String(const wxString& str)
{