StringUtil: Add StartsWithNoCase/EndsWithNoCase

This commit is contained in:
Connor McLaughlin 2022-03-12 23:56:58 +10:00 committed by refractionpcsx2
parent c65ccaa153
commit 444e650711
1 changed files with 11 additions and 0 deletions

View File

@ -153,6 +153,17 @@ namespace StringUtil
return (str.length() >= suffix_length && str.compare(str.length() - suffix_length, suffix_length, suffix) == 0); return (str.length() >= suffix_length && str.compare(str.length() - suffix_length, suffix_length, suffix) == 0);
} }
/// StartsWith/EndsWith variants which aren't case sensitive.
static inline bool StartsWithNoCase(const std::string_view& str, const char* prefix)
{
return (Strncasecmp(str.data(), prefix, std::strlen(prefix)) == 0);
}
static inline bool EndsWithNoCase(const std::string_view& str, const char* suffix)
{
const std::size_t suffix_length = std::strlen(suffix);
return (str.length() >= suffix_length && Strncasecmp(str.data() + (str.length() - suffix_length), suffix, suffix_length) == 0);
}
/// 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);