From 85b072b3d31fa70a2f563a3202a80031b9209b49 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 13 Mar 2020 20:36:48 +0100 Subject: [PATCH] util/StringCompare: add StringIsEqual() with string_view --- src/util/StringCompare.hxx | 16 ++++++++++++++++ src/util/WStringCompare.hxx | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/util/StringCompare.hxx b/src/util/StringCompare.hxx index b13f1623c..b667b8c80 100644 --- a/src/util/StringCompare.hxx +++ b/src/util/StringCompare.hxx @@ -45,6 +45,22 @@ StringIsEmpty(const char *string) noexcept return *string == 0; } +gcc_pure +static inline bool +StringIsEqual(std::string_view a, std::string_view b) noexcept +{ + return a.size() == b.size() && + StringIsEqual(a.data(), b.data(), b.size()); +} + +gcc_pure +static inline bool +StringIsEqualIgnoreCase(std::string_view a, std::string_view b) noexcept +{ + return a.size() == b.size() && + StringIsEqualIgnoreCase(a.data(), b.data(), b.size()); +} + gcc_pure gcc_nonnull_all static inline bool StringStartsWith(const char *haystack, StringView needle) noexcept diff --git a/src/util/WStringCompare.hxx b/src/util/WStringCompare.hxx index 99ec8ddfb..6b3c60350 100644 --- a/src/util/WStringCompare.hxx +++ b/src/util/WStringCompare.hxx @@ -43,6 +43,22 @@ StringIsEmpty(const wchar_t *string) noexcept return *string == 0; } +gcc_pure +static inline bool +StringIsEqual(std::wstring_view a, std::wstring_view b) noexcept +{ + return a.size() == b.size() && + StringIsEqual(a.data(), b.data(), b.size()); +} + +gcc_pure +static inline bool +StringIsEqualIgnoreCase(std::wstring_view a, std::wstring_view b) noexcept +{ + return a.size() == b.size() && + StringIsEqualIgnoreCase(a.data(), b.data(), b.size()); +} + gcc_pure gcc_nonnull_all static inline bool StringStartsWith(const wchar_t *haystack, WStringView needle) noexcept