mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
AK: Implement String::find_any_of() and StringView::find_any_of()
This implements StringUtils::find_any_of() and uses it in
String::find_any_of() and StringView::find_any_of(). All uses of
find_{first,last}_of have been replaced with find_any_of(), find() or
find_last(). find_{first,last}_of have subsequently been removed.
This commit is contained in:
committed by
Andreas Kling
parent
17eddf3ac4
commit
9cc35d1ba3
@@ -238,33 +238,6 @@ bool StringView::operator==(const String& string) const
|
||||
return !__builtin_memcmp(m_characters, string.characters(), m_length);
|
||||
}
|
||||
|
||||
Optional<size_t> StringView::find_first_of(const StringView& view) const
|
||||
{
|
||||
if (const auto location = AK::find_if(begin(), end(),
|
||||
[&](const auto c) {
|
||||
return any_of(view.begin(), view.end(),
|
||||
[&](const auto view_char) {
|
||||
return c == view_char;
|
||||
});
|
||||
});
|
||||
location != end()) {
|
||||
return location.index();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<size_t> StringView::find_last_of(const StringView& view) const
|
||||
{
|
||||
for (size_t pos = m_length; pos != 0; --pos) {
|
||||
char c = m_characters[pos - 1];
|
||||
for (char view_char : view) {
|
||||
if (c == view_char)
|
||||
return pos - 1;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
String StringView::to_string() const { return String { *this }; }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user