mirror of
https://github.com/PCSX2/pcsx2.git
synced 2026-12-03 19:33:33 +01:00
StringUtil: Add SplitString()
This commit is contained in:
1 parent
551d013b63
commit
e5248db844
2 files changed
+27
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user