mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 13:19:05 +00:00
AK: Add a keep_empty argument to String[View]::substring{_view}
This commit is contained in:
parent
07ca753124
commit
127d168def
Notes:
sideshowbarker
2024-07-19 11:58:03 +09:00
Author: https://github.com/bugaevc
Commit: 127d168def
Pull-request: https://github.com/SerenityOS/serenity/pull/609
Reviewed-by: https://github.com/awesomekling ✅
4 changed files with 10 additions and 10 deletions
|
@ -16,7 +16,7 @@ StringView::StringView(const ByteBuffer& buffer)
|
|||
{
|
||||
}
|
||||
|
||||
Vector<StringView> StringView::split_view(const char separator) const
|
||||
Vector<StringView> StringView::split_view(const char separator, bool keep_empty) const
|
||||
{
|
||||
if (is_empty())
|
||||
return {};
|
||||
|
@ -27,15 +27,15 @@ Vector<StringView> StringView::split_view(const char separator) const
|
|||
char ch = characters_without_null_termination()[i];
|
||||
if (ch == separator) {
|
||||
ssize_t sublen = i - substart;
|
||||
if (sublen != 0)
|
||||
if (sublen != 0 || keep_empty)
|
||||
v.append(substring_view(substart, sublen));
|
||||
substart = i + 1;
|
||||
}
|
||||
}
|
||||
ssize_t taillen = length() - substart;
|
||||
if (taillen != 0)
|
||||
if (taillen != 0 || keep_empty)
|
||||
v.append(substring_view(substart, taillen));
|
||||
if (characters_without_null_termination()[length() - 1] == separator)
|
||||
if (characters_without_null_termination()[length() - 1] == separator && keep_empty)
|
||||
v.append(String::empty());
|
||||
return v;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue