mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 07:24:58 +00:00
AK: Rewrite StringView::split_view(char..), using StringView
This commit is contained in:
parent
faf1fa0a84
commit
cd42f64bc7
1 changed files with 2 additions and 18 deletions
|
@ -36,24 +36,8 @@ StringView::StringView(const ByteBuffer& buffer)
|
|||
|
||||
Vector<StringView> StringView::split_view(const char separator, 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 (ch == separator) {
|
||||
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;
|
||||
StringView seperator_view { &separator, 1 };
|
||||
return split_view(seperator_view, keep_empty);
|
||||
}
|
||||
|
||||
Vector<StringView> StringView::split_view(StringView separator, bool keep_empty) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue