mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 23:25:20 +00:00
AK: Add StringView::starts_with(char) & StringView::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:
committed by
Andreas Kling
parent
a406a8c7d2
commit
854f0b9e1a
@@ -105,6 +105,13 @@ Vector<StringView> StringView::lines(bool consider_cr) const
|
||||
return v;
|
||||
}
|
||||
|
||||
bool StringView::starts_with(char ch) const
|
||||
{
|
||||
if (is_empty())
|
||||
return false;
|
||||
return ch == characters_without_null_termination()[0];
|
||||
}
|
||||
|
||||
bool StringView::starts_with(const StringView& str) const
|
||||
{
|
||||
if (str.is_empty())
|
||||
@@ -118,6 +125,13 @@ bool StringView::starts_with(const StringView& str) const
|
||||
return !memcmp(characters_without_null_termination(), str.characters_without_null_termination(), str.length());
|
||||
}
|
||||
|
||||
bool StringView::ends_with(char ch) const
|
||||
{
|
||||
if (is_empty())
|
||||
return false;
|
||||
return ch == characters_without_null_termination()[length() - 1];
|
||||
}
|
||||
|
||||
bool StringView::ends_with(const StringView& str) const
|
||||
{
|
||||
if (str.is_empty())
|
||||
|
||||
Reference in New Issue
Block a user