Skip to content

Commit b16b24c

Browse files
committed
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.)
1 parent f6c4304 commit b16b24c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

AK/Utf8View.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ bool Utf8View::contains(u32 needle) const
120120
return false;
121121
}
122122

123+
bool Utf8View::contains_any_of(ReadonlySpan<u32> needles) const
124+
{
125+
for (u32 const code_point : *this) {
126+
for (auto needle : needles) {
127+
if (code_point == needle)
128+
return true;
129+
}
130+
}
131+
132+
return false;
133+
}
134+
123135
Utf8View Utf8View::trim(Utf8View const& characters, TrimMode mode) const
124136
{
125137
size_t substring_start = 0;

AK/Utf8View.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class Utf8View {
115115
bool is_null() const { return m_string.is_null(); }
116116
bool starts_with(Utf8View const&) const;
117117
bool contains(u32) const;
118+
bool contains_any_of(ReadonlySpan<u32>) const;
118119

119120
Utf8View trim(Utf8View const& characters, TrimMode mode = TrimMode::Both) const;
120121

0 commit comments

Comments
 (0)