mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Add StringView::contains(char)
This commit is contained in:
parent
1f6578ee0a
commit
b77ceecb02
Notes:
sideshowbarker
2024-07-19 07:32:10 +09:00
Author: https://github.com/sunverwerth Commit: https://github.com/SerenityOS/serenity/commit/b77ceecb02a Pull-request: https://github.com/SerenityOS/serenity/pull/1826
2 changed files with 11 additions and 1 deletions
|
@ -25,10 +25,10 @@
|
|||
*/
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
namespace AK {
|
||||
|
@ -157,6 +157,15 @@ bool StringView::matches(const StringView& mask, CaseSensitivity case_sensitivit
|
|||
return StringUtils::matches(*this, mask, case_sensitivity);
|
||||
}
|
||||
|
||||
bool StringView::contains(char needle) const
|
||||
{
|
||||
for (char current : *this) {
|
||||
if (current == needle)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
StringView StringView::substring_view(size_t start, size_t length) const
|
||||
{
|
||||
ASSERT(start + length <= m_length);
|
||||
|
|
|
@ -73,6 +73,7 @@ public:
|
|||
bool starts_with(char) const;
|
||||
bool ends_with(char) const;
|
||||
bool matches(const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
|
||||
bool contains(char) const;
|
||||
|
||||
StringView substring_view(size_t start, size_t length) const;
|
||||
Vector<StringView> split_view(char, bool keep_empty = false) const;
|
||||
|
|
Loading…
Reference in a new issue