util/StringCompare: move code from StringView

This commit is contained in:
Max Kellermann 2022-06-30 21:07:35 +02:00
parent 5ec13c0b06
commit c5f037fa64
1 changed files with 22 additions and 0 deletions

View File

@ -139,4 +139,26 @@ StringAfterPrefixIgnoreCase(std::string_view haystack,
const char *
FindStringSuffix(const char *p, const char *suffix) noexcept;
template<typename T>
bool
SkipPrefix(std::basic_string_view<T> &haystack,
std::basic_string_view<T> needle) noexcept
{
bool match = haystack.starts_with(needle);
if (match)
haystack.remove_prefix(needle.size());
return match;
}
template<typename T>
bool
RemoveSuffix(std::basic_string_view<T> &haystack,
std::basic_string_view<T> needle) noexcept
{
bool match = haystack.ends_with(needle);
if (match)
haystack.remove_suffix(needle.size());
return match;
}
#endif