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

AK+Everywhere: Remove StringView::find_{first,last}_of(char) methods

This removes StringView::find_first_of(char) and find_last_of(char) and
replaces all its usages with find and find_last respectively. This is
because those two methods are functionally equivalent.
find_{first,last}_of should only be used if searching for multiple
different characters, which is never the case with the char argument.

This also adds the [[nodiscard]] to the remaining find_{first,last}_of
methods.
This commit is contained in:
Max Wipfli 2021-07-01 15:01:29 +02:00 committed by Andreas Kling
parent 56253bf389
commit 3bdaed501e
10 changed files with 41 additions and 68 deletions

View file

@ -104,52 +104,45 @@ TEST_CASE(lines)
EXPECT_EQ(test_string_vector.at(2).is_empty(), true);
}
TEST_CASE(find)
{
auto test_string_view = "aabbcc_xy_ccbbaa"sv;
EXPECT_EQ(test_string_view.find('b'), 2U);
EXPECT_EQ(test_string_view.find('_'), 6U);
EXPECT_EQ(test_string_view.find('n').has_value(), false);
}
TEST_CASE(find_last)
{
auto test_string_view = "aabbcc_xy_ccbbaa"sv;
EXPECT_EQ(test_string_view.find_last('b'), 13U);
EXPECT_EQ(test_string_view.find_last('_'), 9U);
EXPECT_EQ(test_string_view.find_last('3').has_value(), false);
test_string_view = "/"sv;
EXPECT_EQ(test_string_view.find_last('/'), 0U);
}
TEST_CASE(find_first_of)
{
String test_string = "aabbcc_xy_ccbbaa";
StringView test_string_view = test_string.view();
EXPECT_EQ(test_string_view.find_first_of('b').has_value(), true);
EXPECT_EQ(test_string_view.find_first_of('b').value(), 2U);
EXPECT_EQ(test_string_view.find_first_of('_').has_value(), true);
EXPECT_EQ(test_string_view.find_first_of('_').value(), 6U);
EXPECT_EQ(test_string_view.find_first_of("bc").has_value(), true);
EXPECT_EQ(test_string_view.find_first_of("bc").value(), 2U);
EXPECT_EQ(test_string_view.find_first_of("yx").has_value(), true);
EXPECT_EQ(test_string_view.find_first_of("yx").value(), 7U);
EXPECT_EQ(test_string_view.find_first_of('n').has_value(), false);
auto test_string_view = "aabbcc_xy_ccbbaa"sv;
EXPECT_EQ(test_string_view.find_first_of("bc"), 2U);
EXPECT_EQ(test_string_view.find_first_of("yx"), 7U);
EXPECT_EQ(test_string_view.find_first_of("defg").has_value(), false);
test_string_view = "/"sv;
EXPECT_EQ(test_string_view.find_first_of("/"), 0U);
}
TEST_CASE(find_last_of)
{
String test_string = "aabbcc_xy_ccbbaa";
StringView test_string_view = test_string.view();
EXPECT_EQ(test_string_view.find_last_of('b').has_value(), true);
EXPECT_EQ(test_string_view.find_last_of('b').value(), 13U);
EXPECT_EQ(test_string_view.find_last_of('_').has_value(), true);
EXPECT_EQ(test_string_view.find_last_of('_').value(), 9U);
EXPECT_EQ(test_string_view.find_last_of("bc").has_value(), true);
EXPECT_EQ(test_string_view.find_last_of("bc").value(), 13U);
EXPECT_EQ(test_string_view.find_last_of("yx").has_value(), true);
EXPECT_EQ(test_string_view.find_last_of("yx").value(), 8U);
EXPECT_EQ(test_string_view.find_last_of('3').has_value(), false);
auto test_string_view = "aabbcc_xy_ccbbaa"sv;
EXPECT_EQ(test_string_view.find_last_of("bc"), 13U);
EXPECT_EQ(test_string_view.find_last_of("yx"), 8U);
EXPECT_EQ(test_string_view.find_last_of("fghi").has_value(), false);
test_string_view = "/";
EXPECT_EQ(test_string_view.find_last_of('/').has_value(), true);
EXPECT_EQ(test_string_view.find_last_of('/').value(), 0U);
EXPECT_EQ(test_string_view.find_last_of("/").has_value(), true);
EXPECT_EQ(test_string_view.find_last_of("/").value(), 0U);
test_string_view = "/"sv;
EXPECT_EQ(test_string_view.find_last_of("/"), 0U);
}
TEST_CASE(split_view)