diff options
author | Max Kellermann <max@musicpd.org> | 2020-03-13 18:47:00 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-03-13 18:49:47 +0100 |
commit | 6876d160cf085fbeb6caacc8a00ab13f7066cf5d (patch) | |
tree | 9da6d7bb3ac5e679409747eaa51b941469635540 /src/util | |
parent | a63d0ee8fcf3028fb4a3b1b4148d31c6f06dbecc (diff) |
util/StringCompare: add more StringView overloads
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/StringCompare.hxx | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/util/StringCompare.hxx b/src/util/StringCompare.hxx index 8ae7b0de2..b13f1623c 100644 --- a/src/util/StringCompare.hxx +++ b/src/util/StringCompare.hxx @@ -81,6 +81,14 @@ StringStartsWithIgnoreCase(const char *haystack, StringView needle) noexcept return StringIsEqualIgnoreCase(haystack, needle.data, needle.size); } +gcc_pure +static inline bool +StringStartsWithIgnoreCase(StringView haystack, StringView needle) noexcept +{ + return haystack.size >= needle.size && + StringIsEqualIgnoreCase(haystack.data, needle.data, needle.size); +} + gcc_pure gcc_nonnull_all static inline const char * StringAfterPrefixIgnoreCase(const char *haystack, StringView needle) noexcept @@ -90,6 +98,16 @@ StringAfterPrefixIgnoreCase(const char *haystack, StringView needle) noexcept : nullptr; } +gcc_pure +static inline StringView +StringAfterPrefixIgnoreCase(StringView haystack, + StringView needle) noexcept +{ + return StringStartsWithIgnoreCase(haystack, needle) + ? haystack.substr(needle.size) + : nullptr; +} + /** * Check if the given string ends with the specified suffix. If yes, * returns the position of the suffix, and nullptr otherwise. |