mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
AK: Rewrite StringView::split_view(char..), using StringView
This commit is contained in:
committed by
Andreas Kling
parent
faf1fa0a84
commit
cd42f64bc7
@@ -36,24 +36,8 @@ StringView::StringView(const ByteBuffer& buffer)
|
|||||||
|
|
||||||
Vector<StringView> StringView::split_view(const char separator, bool keep_empty) const
|
Vector<StringView> StringView::split_view(const char separator, bool keep_empty) const
|
||||||
{
|
{
|
||||||
if (is_empty())
|
StringView seperator_view { &separator, 1 };
|
||||||
return {};
|
return split_view(seperator_view, keep_empty);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<StringView> StringView::split_view(StringView separator, bool keep_empty) const
|
Vector<StringView> StringView::split_view(StringView separator, bool keep_empty) const
|
||||||
|
|||||||
Reference in New Issue
Block a user