mirror of https://github.com/PCSX2/pcsx2.git
StringUtil: Add SplitString()
This commit is contained in:
parent
551d013b63
commit
e5248db844
|
@ -251,6 +251,30 @@ namespace StringUtil
|
||||||
return str.substr(start, end - start + 1);
|
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 UTF8StringToWideString(const std::string_view& str)
|
||||||
{
|
{
|
||||||
std::wstring ret;
|
std::wstring ret;
|
||||||
|
|
|
@ -167,6 +167,9 @@ namespace StringUtil
|
||||||
/// Strip whitespace from the start/end of the string.
|
/// Strip whitespace from the start/end of the string.
|
||||||
std::string_view StripWhitespace(const std::string_view& str);
|
std::string_view StripWhitespace(const std::string_view& str);
|
||||||
|
|
||||||
|
/// Splits a string based on a single character delimiter.
|
||||||
|
std::vector<std::string_view> SplitString(const std::string_view& str, char delimiter, bool skip_empty = true);
|
||||||
|
|
||||||
/// Strided memcpy/memcmp.
|
/// Strided memcpy/memcmp.
|
||||||
static inline void StrideMemCpy(void* dst, std::size_t dst_stride, const void* src, std::size_t src_stride,
|
static inline void StrideMemCpy(void* dst, std::size_t dst_stride, const void* src, std::size_t src_stride,
|
||||||
std::size_t copy_size, std::size_t count)
|
std::size_t copy_size, std::size_t count)
|
||||||
|
|
Loading…
Reference in New Issue