StringUtil: Add SplitString()

This commit is contained in:
Connor McLaughlin authored and refractionpcsx2 committed 2022-03-25 12:51:31 +00:00
1 parent 551d013b63
commit e5248db844
2 files changed
+27

No files matched your search

+24
View File
@@ -251,6 +251,30 @@ namespace StringUtil
return str.substr(start, end - start + 1);
}
std::vector<std::string_view> SplitString(const std::string_view& str, char delimiter, bool skip_empty /*= true*/)
{
std::vector<std::string_view> res;
std::string_view::size_type last_pos = 0;
std::string_view::size_type pos;
while (last_pos < str.size() && (pos = str.find(delimiter, last_pos)) != std::string_view::npos)
{
std::string_view part(StripWhitespace(str.substr(last_pos, pos - last_pos)));
if (!skip_empty || !part.empty())
res.push_back(std::move(part));
last_pos = pos + 1;
}
if (last_pos < str.size())
{
std::string_view part(StripWhitespace(str.substr(last_pos)));
if (!skip_empty || !part.empty())
res.push_back(std::move(part));
}
return res;
}
std::wstring UTF8StringToWideString(const std::string_view& str)
{
std::wstring ret;