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

View File

@ -139,4 +139,26 @@ StringAfterPrefixIgnoreCase(std::string_view haystack,
const char * const char *
FindStringSuffix(const char *p, const char *suffix) noexcept; 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 #endif