mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
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:
parent
f6c4304e89
commit
b16b24c615
Notes:
github-actions[bot]
2025-02-04 08:50:31 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/b16b24c6153 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3181 Reviewed-by: https://github.com/trflynn89
2 changed files with 13 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue