mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 11:45:06 +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:
parent
0e3a9d8e9d
commit
9920d17342
3 changed files with 19 additions and 0 deletions
|
@ -295,6 +295,13 @@ bool String::starts_with(const StringView& str) const
|
|||
return !memcmp(characters(), str.characters_without_null_termination(), str.length());
|
||||
}
|
||||
|
||||
bool String::starts_with(char ch) const
|
||||
{
|
||||
if (is_empty())
|
||||
return false;
|
||||
return characters()[0] == ch;
|
||||
}
|
||||
|
||||
bool String::ends_with(const StringView& str) const
|
||||
{
|
||||
if (str.is_empty())
|
||||
|
@ -306,6 +313,12 @@ bool String::ends_with(const StringView& str) const
|
|||
return !memcmp(characters() + (length() - str.length()), str.characters_without_null_termination(), str.length());
|
||||
}
|
||||
|
||||
bool String::ends_with(char ch) const
|
||||
{
|
||||
if (is_empty())
|
||||
return false;
|
||||
return characters()[length() - 1] == ch;
|
||||
}
|
||||
String String::repeated(char ch, size_t count)
|
||||
{
|
||||
if (!count)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue