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 f7626d07e9dd270645b37264230e85e5acb16ddc..e4221f037f2ff375b01c1c8e633e829206f41c4d 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 821b706b90250498d91438b6612009a455fd92d5..d37ee4d8c9462bc4dacb3dd7c2d91e3ca522b6c6 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 };