mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:44:58 +00:00
AK+Everywhere: Stop including Vector.h from StringView.h
Preparation for using Error.h from Vector.h. This required moving some things out of line.
This commit is contained in:
parent
e52f987020
commit
5f7d008791
27 changed files with 88 additions and 51 deletions
|
@ -8,9 +8,11 @@
|
|||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Find.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
@ -252,4 +254,31 @@ String StringView::replace(const StringView& needle, const StringView& replaceme
|
|||
return StringUtils::replace(*this, needle, replacement, all_occurrences);
|
||||
}
|
||||
|
||||
Vector<size_t> StringView::find_all(StringView needle) const
|
||||
{
|
||||
return StringUtils::find_all(*this, needle);
|
||||
}
|
||||
|
||||
Vector<StringView> StringView::split_view_if(Function<bool(char)> const& predicate, bool keep_empty) const
|
||||
{
|
||||
if (is_empty())
|
||||
return {};
|
||||
|
||||
Vector<StringView> v;
|
||||
size_t substart = 0;
|
||||
for (size_t i = 0; i < length(); ++i) {
|
||||
char ch = characters_without_null_termination()[i];
|
||||
if (predicate(ch)) {
|
||||
size_t sublen = i - substart;
|
||||
if (sublen != 0 || keep_empty)
|
||||
v.append(substring_view(substart, sublen));
|
||||
substart = i + 1;
|
||||
}
|
||||
}
|
||||
size_t taillen = length() - substart;
|
||||
if (taillen != 0 || keep_empty)
|
||||
v.append(substring_view(substart, taillen));
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue