mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Add FlyString::is_one_of for variadic string comparison
This commit is contained in:
parent
3aa485aa09
commit
d6cf9f5329
Notes:
sideshowbarker
2024-07-16 23:52:22 +09:00
Author: https://github.com/kennethmyhra Commit: https://github.com/SerenityOS/serenity/commit/d6cf9f5329 Pull-request: https://github.com/SerenityOS/serenity/pull/17825 Reviewed-by: https://github.com/linusg ✅ Reviewed-by: https://github.com/trflynn89
2 changed files with 22 additions and 0 deletions
|
@ -58,6 +58,12 @@ public:
|
|||
// Compare this FlyString against another string with ASCII caseless matching.
|
||||
[[nodiscard]] bool equals_ignoring_ascii_case(FlyString const&) const;
|
||||
|
||||
template<typename... Ts>
|
||||
[[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts... strings) const
|
||||
{
|
||||
return (... || this->operator==(forward<Ts>(strings)));
|
||||
}
|
||||
|
||||
private:
|
||||
// This will hold either the pointer to the Detail::StringData it represents or the raw bytes of
|
||||
// an inlined short string.
|
||||
|
|
|
@ -118,3 +118,19 @@ TEST_CASE(moved_fly_string_becomes_empty)
|
|||
EXPECT_EQ(fly1, "thisisdefinitelymorethan7bytes"sv);
|
||||
EXPECT_EQ(FlyString::number_of_fly_strings(), 1u);
|
||||
}
|
||||
|
||||
TEST_CASE(is_one_of)
|
||||
{
|
||||
auto foo = MUST(FlyString::from_utf8("foo"sv));
|
||||
auto bar = MUST(FlyString::from_utf8("bar"sv));
|
||||
|
||||
EXPECT(foo.is_one_of(foo));
|
||||
EXPECT(foo.is_one_of(foo, bar));
|
||||
EXPECT(foo.is_one_of(bar, foo));
|
||||
EXPECT(!foo.is_one_of(bar));
|
||||
|
||||
EXPECT(!bar.is_one_of("foo"sv));
|
||||
EXPECT(bar.is_one_of("foo"sv, "bar"sv));
|
||||
EXPECT(bar.is_one_of("bar"sv, "foo"sv));
|
||||
EXPECT(bar.is_one_of("bar"sv));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue