Skip to content

Commit

Permalink
AK: StringView::lines() should keep empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Dec 2, 2019
1 parent d422c46 commit 8f80879
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions AK/StringView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ Vector<StringView> StringView::lines(bool consider_cr) const
}
if (split_view) {
ssize_t sublen = i - substart;
if (sublen != 0)
v.append(substring_view(substart, sublen));
v.append(substring_view(substart, sublen));
substart = i + 1;
}
split_view = false;
Expand Down
8 changes: 8 additions & 0 deletions AK/Tests/TestStringView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ TEST_CASE(lines)
EXPECT(test_string_vector.at(1) == String("Hello there"));
EXPECT(test_string_vector.at(2) == String("Hello there"));
EXPECT(test_string_vector.at(3) == String("```"));

test_string = "\n\n\n";
test_string_view = test_string.view();
test_string_vector = test_string_view.lines();
EXPECT_EQ(test_string_vector.size(), 3);
EXPECT_EQ(test_string_vector.at(0).is_empty(), true);
EXPECT_EQ(test_string_vector.at(1).is_empty(), true);
EXPECT_EQ(test_string_vector.at(2).is_empty(), true);
}

TEST_MAIN(StringView)

0 comments on commit 8f80879

Please sign in to comment.