mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
StringView: Add starts_with method
This commit is contained in:
parent
6d7c928359
commit
05f641a5a9
Notes:
sideshowbarker
2024-07-19 12:08:40 +09:00
Author: https://github.com/MinusGix Commit: https://github.com/SerenityOS/serenity/commit/05f641a5a91 Pull-request: https://github.com/SerenityOS/serenity/pull/545
2 changed files with 15 additions and 0 deletions
|
@ -40,6 +40,19 @@ Vector<StringView> StringView::split_view(const char separator) const
|
|||
return v;
|
||||
}
|
||||
|
||||
bool StringView::starts_with(const StringView& str) const
|
||||
{
|
||||
if (str.is_empty())
|
||||
return true;
|
||||
if (is_empty())
|
||||
return false;
|
||||
if (str.length() > length())
|
||||
return false;
|
||||
if (characters_without_null_termination() == str.characters_without_null_termination())
|
||||
return true;
|
||||
return !memcmp(characters_without_null_termination(), str.characters_without_null_termination(), str.length());
|
||||
}
|
||||
|
||||
StringView StringView::substring_view(int start, int length) const
|
||||
{
|
||||
if (!length)
|
||||
|
|
|
@ -41,6 +41,8 @@ public:
|
|||
|
||||
unsigned hash() const;
|
||||
|
||||
bool starts_with(const StringView&) const;
|
||||
|
||||
StringView substring_view(int start, int length) const;
|
||||
Vector<StringView> split_view(char) const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue