mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
AK: Add FlyString::is_one_of for variadic string comparison
This commit is contained in:
committed by
Linus Groh
parent
3aa485aa09
commit
d6cf9f5329
@@ -58,6 +58,12 @@ public:
|
|||||||
// Compare this FlyString against another string with ASCII caseless matching.
|
// Compare this FlyString against another string with ASCII caseless matching.
|
||||||
[[nodiscard]] bool equals_ignoring_ascii_case(FlyString const&) const;
|
[[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:
|
private:
|
||||||
// This will hold either the pointer to the Detail::StringData it represents or the raw bytes of
|
// This will hold either the pointer to the Detail::StringData it represents or the raw bytes of
|
||||||
// an inlined short string.
|
// an inlined short string.
|
||||||
|
|||||||
@@ -118,3 +118,19 @@ TEST_CASE(moved_fly_string_becomes_empty)
|
|||||||
EXPECT_EQ(fly1, "thisisdefinitelymorethan7bytes"sv);
|
EXPECT_EQ(fly1, "thisisdefinitelymorethan7bytes"sv);
|
||||||
EXPECT_EQ(FlyString::number_of_fly_strings(), 1u);
|
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));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user