From c5f037fa641cfc4390c7a5b43d96656ce84377ff Mon Sep 17 00:00:00 2001 From: Max Kellermann <max.kellermann@gmail.com> Date: Thu, 30 Jun 2022 21:07:35 +0200 Subject: [PATCH] util/StringCompare: move code from StringView --- src/util/StringCompare.hxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/util/StringCompare.hxx b/src/util/StringCompare.hxx index a5d2b2ed1..620f3931f 100644 --- a/src/util/StringCompare.hxx +++ b/src/util/StringCompare.hxx @@ -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