mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:58:11 +00:00
AK: Make String::matches() capable of reporting match positions too
Also, rewrite StringUtils::match(), because the old implementation was fairly broken, e.g. "acdcxb" would *not* match "a*?b".
This commit is contained in:
parent
2d6d1ca67f
commit
0801b1fada
7 changed files with 86 additions and 33 deletions
|
@ -67,6 +67,25 @@ TEST_CASE(matches_case_insensitive)
|
|||
EXPECT(!AK::StringUtils::matches("acdcb", "a*c?b"));
|
||||
}
|
||||
|
||||
TEST_CASE(matches_with_positions)
|
||||
{
|
||||
Vector<AK::MaskSpan> spans;
|
||||
EXPECT(AK::StringUtils::matches("abbb", "a*", CaseSensitivity::CaseSensitive, &spans));
|
||||
EXPECT(spans == Vector<AK::MaskSpan>({ { 1, 3 } }));
|
||||
|
||||
spans.clear();
|
||||
EXPECT(AK::StringUtils::matches("abbb", "?*", CaseSensitivity::CaseSensitive, &spans));
|
||||
EXPECT_EQ(spans, Vector<AK::MaskSpan>({ { 0, 1 }, { 1, 3 } }));
|
||||
|
||||
spans.clear();
|
||||
EXPECT(AK::StringUtils::matches("acdcxb", "a*c?b", CaseSensitivity::CaseSensitive, &spans));
|
||||
EXPECT_EQ(spans, Vector<AK::MaskSpan>({ { 1, 2 }, { 4, 1 } }));
|
||||
|
||||
spans.clear();
|
||||
EXPECT(AK::StringUtils::matches("aaaa", "A*", CaseSensitivity::CaseInsensitive, &spans));
|
||||
EXPECT_EQ(spans, Vector<AK::MaskSpan>({ { 1, 3 } }));
|
||||
}
|
||||
|
||||
TEST_CASE(convert_to_int)
|
||||
{
|
||||
auto value = AK::StringUtils::convert_to_int(StringView());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue