mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Add String::starts_with to match String::ends_with
This commit is contained in:
parent
738f9de9a9
commit
419e886497
Notes:
sideshowbarker
2024-07-19 13:44:41 +09:00
Author: https://github.com/deoxxa Commit: https://github.com/SerenityOS/serenity/commit/419e886497c Pull-request: https://github.com/SerenityOS/serenity/pull/193
2 changed files with 12 additions and 0 deletions
|
@ -126,6 +126,7 @@ public:
|
|||
return (*m_impl)[i];
|
||||
}
|
||||
|
||||
bool starts_with(const StringView&) const;
|
||||
bool ends_with(const StringView&) const;
|
||||
|
||||
bool operator==(const String&) const;
|
||||
|
|
|
@ -180,6 +180,17 @@ String String::format(const char* fmt, ...)
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
bool String::starts_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(), str.characters(), str.length());
|
||||
}
|
||||
|
||||
bool String::ends_with(const StringView& str) const
|
||||
{
|
||||
if (str.is_empty())
|
||||
|
|
Loading…
Reference in a new issue