mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Also add a keep_empty argument to String::split[_limit]()
Just like String[View]::split_view() has already.
This commit is contained in:
parent
9cbce68b1d
commit
6a64077ed7
Notes:
sideshowbarker
2024-07-19 09:53:37 +09:00
Author: https://github.com/bugaevc Commit: https://github.com/SerenityOS/serenity/commit/6a64077ed78 Pull-request: https://github.com/SerenityOS/serenity/pull/1115
2 changed files with 7 additions and 9 deletions
|
@ -131,12 +131,12 @@ StringView String::substring_view(size_t start, size_t length) const
|
|||
return { characters() + start, length };
|
||||
}
|
||||
|
||||
Vector<String> String::split(const char separator) const
|
||||
Vector<String> String::split(char separator, bool keep_empty) const
|
||||
{
|
||||
return split_limit(separator, 0);
|
||||
return split_limit(separator, 0, keep_empty);
|
||||
}
|
||||
|
||||
Vector<String> String::split_limit(const char separator, size_t limit) const
|
||||
Vector<String> String::split_limit(char separator, size_t limit, bool keep_empty) const
|
||||
{
|
||||
if (is_empty())
|
||||
return {};
|
||||
|
@ -147,16 +147,14 @@ Vector<String> String::split_limit(const char separator, size_t limit) const
|
|||
char ch = characters()[i];
|
||||
if (ch == separator) {
|
||||
size_t sublen = i - substart;
|
||||
if (sublen != 0)
|
||||
if (sublen != 0 || keep_empty)
|
||||
v.append(substring(substart, sublen));
|
||||
substart = i + 1;
|
||||
}
|
||||
}
|
||||
size_t taillen = length() - substart;
|
||||
if (taillen != 0)
|
||||
if (taillen != 0 || keep_empty)
|
||||
v.append(substring(substart, taillen));
|
||||
if (characters()[length() - 1] == separator)
|
||||
v.append(empty());
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
|
@ -140,8 +140,8 @@ public:
|
|||
|
||||
bool contains(const String&) const;
|
||||
|
||||
Vector<String> split_limit(char separator, size_t limit) const;
|
||||
Vector<String> split(char separator) const;
|
||||
Vector<String> split_limit(char separator, size_t limit, bool keep_empty = false) const;
|
||||
Vector<String> split(char separator, bool keep_empty = false) const;
|
||||
String substring(size_t start, size_t length) const;
|
||||
|
||||
Vector<StringView> split_view(char separator, bool keep_empty = false) const;
|
||||
|
|
Loading…
Reference in a new issue