mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:14:58 +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:
parent
17eddf3ac4
commit
9cc35d1ba3
12 changed files with 44 additions and 52 deletions
|
@ -378,6 +378,24 @@ Vector<size_t> find_all(StringView const& haystack, StringView const& needle)
|
|||
return positions;
|
||||
}
|
||||
|
||||
Optional<size_t> find_any_of(StringView const& haystack, StringView const& needles, SearchDirection direction)
|
||||
{
|
||||
if (haystack.is_empty() || needles.is_empty())
|
||||
return {};
|
||||
if (direction == SearchDirection::Forward) {
|
||||
for (size_t i = 0; i < haystack.length(); ++i) {
|
||||
if (needles.contains(haystack[i]))
|
||||
return i;
|
||||
}
|
||||
} else if (direction == SearchDirection::Backward) {
|
||||
for (size_t i = haystack.length(); i > 0; --i) {
|
||||
if (needles.contains(haystack[i - 1]))
|
||||
return i - 1;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
String to_snakecase(const StringView& str)
|
||||
{
|
||||
auto should_insert_underscore = [&](auto i, auto current_char) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue