1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:58:13 +00:00

AK: Add StringView::ends_with function

This commit is contained in:
Shannon Booth 2019-12-30 01:44:30 +13:00 committed by Andreas Kling
parent 27df4eb43d
commit 24bc674d94
3 changed files with 22 additions and 0 deletions

View file

@ -92,6 +92,17 @@ 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(const StringView& str) const
{
if (str.is_empty())
return true;
if (is_empty())
return false;
if (str.length() > length())
return false;
return !memcmp(characters_without_null_termination() + length() - str.length(), str.characters_without_null_termination(), str.length());
}
StringView StringView::substring_view(size_t start, size_t length) const
{
if (!length)