1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 11:17:44 +00:00

AK: Add String{View,}::find(StringView)

I personally mistook `find_first_of(StringView)` to be analogous to this
so let's add a `find()` method that actually searches the string.
This commit is contained in:
AnotherTest 2021-01-12 23:28:45 +03:30 committed by Andreas Kling
parent 4fa8435310
commit 39442e6d4f
8 changed files with 70 additions and 11 deletions

View file

@ -298,4 +298,16 @@ TEST_CASE(is_whitespace)
EXPECT(!AK::StringUtils::is_whitespace("a\t"));
}
TEST_CASE(find)
{
String test_string = "1234567";
EXPECT_EQ(AK::StringUtils::find(test_string, "1").value_or(1), 0u);
EXPECT_EQ(AK::StringUtils::find(test_string, "2").value_or(2), 1u);
EXPECT_EQ(AK::StringUtils::find(test_string, "3").value_or(3), 2u);
EXPECT_EQ(AK::StringUtils::find(test_string, "4").value_or(4), 3u);
EXPECT_EQ(AK::StringUtils::find(test_string, "5").value_or(5), 4u);
EXPECT_EQ(AK::StringUtils::find(test_string, "34").value_or(3), 2u);
EXPECT_EQ(AK::StringUtils::find(test_string, "78").has_value(), false);
}
TEST_MAIN(StringUtils)