1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 23:38:11 +00:00

AK: Add String starts_with(char) & ends_with(char)

This is simply meant to be a more efficient implementation in the
case that we only need to check a single character.
This commit is contained in:
Shannon Booth 2020-02-15 13:04:00 +13:00 committed by Andreas Kling
parent 0e3a9d8e9d
commit 9920d17342
3 changed files with 19 additions and 0 deletions

View file

@ -80,6 +80,8 @@ TEST_CASE(starts_with)
{
String test_string = "ABCDEF";
EXPECT(test_string.starts_with("AB"));
EXPECT(test_string.starts_with('A'));
EXPECT(!test_string.starts_with('B'));
EXPECT(test_string.starts_with("ABCDEF"));
EXPECT(!test_string.starts_with("DEF"));
}
@ -88,6 +90,8 @@ TEST_CASE(ends_with)
{
String test_string = "ABCDEF";
EXPECT(test_string.ends_with("EF"));
EXPECT(test_string.ends_with('F'));
EXPECT(!test_string.ends_with('E'));
EXPECT(test_string.ends_with("ABCDEF"));
EXPECT(!test_string.ends_with("ABC"));
}