AK: Fix String[View]::split_view() returning an extra empty part

If the last character was the separator and keep_empty is true, the
previous if statement would have already appended the last empty part,
so no need to do this again.

This was even more problematic, because the result of split_view() is
expected to consist of true substrings that are usable with the
StringView::substring_view_starting_*_substring() methods, not of
equal strings located elsewhere.

Fixes https://github.com/SerenityOS/serenity/issues/970
See https://github.com/SerenityOS/serenity/pull/938
This commit is contained in:
Sergey Bugaev 2020-01-14 13:26:22 +03:00 committed by Andreas Kling
parent 7ad9bfbc68
commit 499612482b
Notes: sideshowbarker 2024-07-19 10:04:00 +09:00
2 changed files with 0 additions and 4 deletions

View file

@ -153,8 +153,6 @@ Vector<StringView> String::split_view(const char separator, bool keep_empty) con
size_t taillen = length() - substart;
if (taillen != 0 || keep_empty)
v.append(substring_view(substart, taillen));
if (characters()[length() - 1] == separator && keep_empty)
v.append(empty());
return v;
}

View file

@ -35,8 +35,6 @@ Vector<StringView> StringView::split_view(const char separator, bool keep_empty)
size_t taillen = length() - substart;
if (taillen != 0 || keep_empty)
v.append(substring_view(substart, taillen));
if (characters_without_null_termination()[length() - 1] == separator && keep_empty)
v.append(String::empty());
return v;
}