From 5a6f0ef1bcd0246075963a9feb9fee5d3aefa4c3 Mon Sep 17 00:00:00 2001 From: R Smith Date: Tue, 1 Jun 2021 23:17:04 +1200 Subject: [PATCH] =?UTF-8?q?AK:=20Don=E2=80=99t=20drop=20lines=20between=20?= =?UTF-8?q?\r=20and=20\n=20in=20StringView::lines()=20(#7662)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit StringView::lines() supports line-separators “\n”, “\r”, and “\r\n”. The method will drop an entire line if it is surrounded by “\r” and “\n” separators on the left and right sides respectively. --- AK/StringView.cpp | 3 ++- Tests/AK/TestStringView.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/AK/StringView.cpp b/AK/StringView.cpp index 4bb4c1b9f4..fe74bc9fd2 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -99,12 +99,13 @@ Vector StringView::lines(bool consider_cr) const if (last_ch_was_cr) { substart = i + 1; split_view = false; - last_ch_was_cr = false; } } if (ch == '\r') { split_view = true; last_ch_was_cr = true; + } else { + last_ch_was_cr = false; } if (split_view) { size_t sublen = i - substart; diff --git a/Tests/AK/TestStringView.cpp b/Tests/AK/TestStringView.cpp index 2ffbdf65fd..f9a786ec77 100644 --- a/Tests/AK/TestStringView.cpp +++ b/Tests/AK/TestStringView.cpp @@ -77,7 +77,7 @@ TEST_CASE(ends_with) TEST_CASE(lines) { - String test_string = "a\nb\r\nc\rd"; + String test_string = "a\rb\nc\r\nd"; StringView test_string_view = test_string.view(); Vector test_string_vector = test_string_view.lines(); EXPECT_EQ(test_string_vector.size(), 4u);