From 820e03e8d4e197063be409c39d582800e98d0259 Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Sun, 20 Mar 2022 23:52:36 +0100 Subject: [PATCH] AK: Add a case insensitive of is_one_of to String[View] --- AK/String.h | 12 ++++++++++++ AK/StringView.h | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/AK/String.h b/AK/String.h index f7626d07e9d..e4221f037f2 100644 --- a/AK/String.h +++ b/AK/String.h @@ -302,6 +302,18 @@ public: return (... || this->operator==(forward(strings))); } + template + [[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of_ignoring_case(Ts&&... strings) const + { + return (... || + [this, &strings]() -> bool { + if constexpr (requires(Ts a) { a.view()->StringView; }) + return this->equals_ignoring_case(forward(strings.view())); + else + return this->equals_ignoring_case(forward(strings)); + }()); + } + private: RefPtr m_impl; }; diff --git a/AK/StringView.h b/AK/StringView.h index 821b706b902..d37ee4d8c94 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -279,6 +279,18 @@ public: return (... || this->operator==(forward(strings))); } + template + [[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of_ignoring_case(Ts&&... strings) const + { + return (... || + [this, &strings]() -> bool { + if constexpr (requires(Ts a) { a.view()->StringView; }) + return this->equals_ignoring_case(forward(strings.view())); + else + return this->equals_ignoring_case(forward(strings)); + }()); + } + private: friend class String; const char* m_characters { nullptr };