AK: Add StringView::contains(char)

This commit is contained in:
Stephan Unverwerth 2020-04-17 15:04:40 +02:00 committed by Andreas Kling
parent 1f6578ee0a
commit b77ceecb02
Notes: sideshowbarker 2024-07-19 07:32:10 +09:00
2 changed files with 11 additions and 1 deletions

View file

@ -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);

View file

@ -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;