AK: Add Utf8View::contains_any_of()

Useful when you need to check for more than one code point, some of
which are multiple bytes. (In which case StringView::contains() will
return wrong results.)
This commit is contained in:
Sam Atkins 2025-01-08 12:56:45 +00:00
parent f6c4304e89
commit b16b24c615
Notes: github-actions[bot] 2025-02-04 08:50:31 +00:00
2 changed files with 13 additions and 0 deletions

View file

@ -120,6 +120,18 @@ bool Utf8View::contains(u32 needle) const
return false;
}
bool Utf8View::contains_any_of(ReadonlySpan<u32> needles) const
{
for (u32 const code_point : *this) {
for (auto needle : needles) {
if (code_point == needle)
return true;
}
}
return false;
}
Utf8View Utf8View::trim(Utf8View const& characters, TrimMode mode) const
{
size_t substring_start = 0;

View file

@ -115,6 +115,7 @@ public:
bool is_null() const { return m_string.is_null(); }
bool starts_with(Utf8View const&) const;
bool contains(u32) const;
bool contains_any_of(ReadonlySpan<u32>) const;
Utf8View trim(Utf8View const& characters, TrimMode mode = TrimMode::Both) const;