mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:58:11 +00:00
AK: Implement StringView::find_all()
This implements the StringView::find_all() method by re-implemeting the current method existing for String in StringUtils, and using that implementation for both String and StringView. The rewrite uses memmem() instead of strstr(), so the String::find_all() argument type has been changed from String to StringView, as the null byte is no longer required.
This commit is contained in:
parent
3bdaed501e
commit
d7a104c27c
4 changed files with 19 additions and 18 deletions
|
@ -293,23 +293,6 @@ bool String::equals_ignoring_case(const StringView& other) const
|
|||
return StringUtils::equals_ignoring_case(view(), other);
|
||||
}
|
||||
|
||||
Vector<size_t> String::find_all(const String& needle) const
|
||||
{
|
||||
Vector<size_t> positions;
|
||||
size_t start = 0, pos;
|
||||
for (;;) {
|
||||
const char* ptr = strstr(characters() + start, needle.characters());
|
||||
if (!ptr)
|
||||
break;
|
||||
|
||||
pos = ptr - characters();
|
||||
positions.append(pos);
|
||||
|
||||
start = pos + 1;
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
int String::replace(const String& needle, const String& replacement, bool all_occurrences)
|
||||
{
|
||||
if (is_empty())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue