mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:27:43 +00:00
AK: Add FlyString::is_one_of for variadic string comparison
This commit is contained in:
parent
3aa485aa09
commit
d6cf9f5329
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…
Add table
Add a link
Reference in a new issue