1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:08:10 +00:00

AK: Add a predicate variant of StringView::split_view

This commit is contained in:
Timothy Flynn 2021-04-12 07:54:22 -04:00 committed by Andreas Kling
parent 0497986572
commit 2370efbea6
3 changed files with 31 additions and 1 deletions

View file

@ -183,6 +183,13 @@ TEST_CASE(split_view)
test_string_view = "axxbcxxdxx";
EXPECT_EQ(test_string_view.split_view("xx"), Vector<StringView>({ "a", "bc", "d" }));
EXPECT_EQ(test_string_view.split_view("xx", true), Vector<StringView>({ "a", "bc", "d", "" }));
test_string_view = "ax_b_cxd";
auto predicate = [](char ch) { return ch == 'x' || ch == '_'; };
EXPECT_EQ(test_string_view.split_view_if(predicate), Vector<StringView>({ "a", "b", "c", "d" }));
EXPECT_EQ(test_string_view.split_view_if(predicate, true), Vector<StringView>({ "a", "", "b", "c", "d" }));
EXPECT_EQ(test_string_view.split_view_if(predicate), Vector<StringView>({ "a", "b", "c", "d" }));
EXPECT_EQ(test_string_view.split_view_if(predicate, true), Vector<StringView>({ "a", "", "b", "c", "d" }));
}
TEST_MAIN(StringView)