Common/StringUtil: Add whitespace strip methods

This commit is contained in:
Connor McLaughlin 2021-12-25 21:02:40 +10:00 committed by refractionpcsx2
parent 1a598ccf0d
commit 92689a60ae
2 changed files with 18 additions and 0 deletions

View File

@ -236,6 +236,21 @@ namespace StringUtil
return lines;
}
std::string_view StripWhitespace(const std::string_view& str)
{
std::string_view::size_type start = 0;
while (start < str.size() && std::isspace(str[start]))
start++;
if (start == str.size())
return {};
std::string_view::size_type end = str.size() - 1;
while (end > start && std::isspace(str[end]))
end--;
return str.substr(start, end - start + 1);
}
std::wstring UTF8StringToWideString(const std::string_view& str)
{
std::wstring ret;

View File

@ -153,6 +153,9 @@ namespace StringUtil
return (str.length() >= suffix_length && str.compare(str.length() - suffix_length, suffix_length, suffix) == 0);
}
/// Strip whitespace from the start/end of the string.
std::string_view StripWhitespace(const std::string_view& str);
/// Strided memcpy/memcmp.
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)