summaryrefslogtreecommitdiff
path: root/AK/String.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'AK/String.cpp')
-rw-r--r--AK/String.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/AK/String.cpp b/AK/String.cpp
index 2497e8c8b4..3c63b70b62 100644
--- a/AK/String.cpp
+++ b/AK/String.cpp
@@ -110,12 +110,13 @@ Vector<String> String::split_limit(char separator, size_t limit, SplitBehavior s
Vector<String> v;
size_t substart = 0;
bool keep_empty = has_flag(split_behavior, SplitBehavior::KeepEmpty);
+ bool keep_separator = has_flag(split_behavior, SplitBehavior::KeepTrailingSeparator);
for (size_t i = 0; i < length() && (v.size() + 1) != limit; ++i) {
char ch = characters()[i];
if (ch == separator) {
size_t sublen = i - substart;
if (sublen != 0 || keep_empty)
- v.append(substring(substart, sublen));
+ v.append(substring(substart, keep_separator ? sublen + 1 : sublen));
substart = i + 1;
}
}
@@ -133,12 +134,13 @@ Vector<StringView> String::split_view(Function<bool(char)> separator, SplitBehav
Vector<StringView> v;
size_t substart = 0;
bool keep_empty = has_flag(split_behavior, SplitBehavior::KeepEmpty);
+ bool keep_separator = has_flag(split_behavior, SplitBehavior::KeepTrailingSeparator);
for (size_t i = 0; i < length(); ++i) {
char ch = characters()[i];
if (separator(ch)) {
size_t sublen = i - substart;
if (sublen != 0 || keep_empty)
- v.append(substring_view(substart, sublen));
+ v.append(substring_view(substart, keep_separator ? sublen + 1 : sublen));
substart = i + 1;
}
}