mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:18:11 +00:00
AK: Unify FlyString/StringView::ends_with implementation on StringUtils::ends_with
This creates a unified implementation of ends_with with case sensitivity across String/StringView/FlyString.
This commit is contained in:
parent
332f96e7ca
commit
129462cca7
4 changed files with 9 additions and 9 deletions
|
@ -98,6 +98,11 @@ bool FlyString::equals_ignoring_case(const StringView& other) const
|
||||||
return StringUtils::equals_ignoring_case(view(), other);
|
return StringUtils::equals_ignoring_case(view(), other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FlyString::ends_with(const StringView& str, CaseSensitivity case_sensitivity) const
|
||||||
|
{
|
||||||
|
return StringUtils::ends_with(view(), str, case_sensitivity);
|
||||||
|
}
|
||||||
|
|
||||||
FlyString FlyString::to_lowercase() const
|
FlyString FlyString::to_lowercase() const
|
||||||
{
|
{
|
||||||
return String(*m_impl).to_lowercase();
|
return String(*m_impl).to_lowercase();
|
||||||
|
|
|
@ -85,6 +85,7 @@ public:
|
||||||
int to_int(bool& ok) const;
|
int to_int(bool& ok) const;
|
||||||
|
|
||||||
bool equals_ignoring_case(const StringView&) const;
|
bool equals_ignoring_case(const StringView&) const;
|
||||||
|
bool ends_with(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
|
||||||
|
|
||||||
static void did_destroy_impl(Badge<StringImpl>, StringImpl&);
|
static void did_destroy_impl(Badge<StringImpl>, StringImpl&);
|
||||||
|
|
||||||
|
|
|
@ -141,15 +141,9 @@ bool StringView::ends_with(char ch) const
|
||||||
return ch == characters_without_null_termination()[length() - 1];
|
return ch == characters_without_null_termination()[length() - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StringView::ends_with(const StringView& str) const
|
bool StringView::ends_with(const StringView& str, CaseSensitivity case_sensitivity) const
|
||||||
{
|
{
|
||||||
if (str.is_empty())
|
return StringUtils::ends_with(*this, str, case_sensitivity);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StringView::matches(const StringView& mask, CaseSensitivity case_sensitivity) const
|
bool StringView::matches(const StringView& mask, CaseSensitivity case_sensitivity) const
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
unsigned hash() const;
|
unsigned hash() const;
|
||||||
|
|
||||||
bool starts_with(const StringView&) const;
|
bool starts_with(const StringView&) const;
|
||||||
bool ends_with(const StringView&) const;
|
bool ends_with(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
|
||||||
bool starts_with(char) const;
|
bool starts_with(char) const;
|
||||||
bool ends_with(char) const;
|
bool ends_with(char) const;
|
||||||
bool matches(const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
|
bool matches(const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue