BAN: Implement find() for StringView

This commit is contained in:
Bananymous 2023-12-23 18:43:52 +02:00
parent f371fabe35
commit 2e77718f07
2 changed files with 21 additions and 1 deletions

View File

@ -145,6 +145,22 @@ namespace BAN
return m_data[0];
}
BAN::Optional<StringView::size_type> StringView::find(char ch) const
{
for (size_type i = 0; i < m_size; i++)
if (m_data[i] == ch)
return i;
return {};
}
BAN::Optional<StringView::size_type> StringView::find(bool(*comp)(char)) const
{
for (size_type i = 0; i < m_size; i++)
if (comp(m_data[i]))
return i;
return {};
}
bool StringView::contains(char ch) const
{
for (size_type i = 0; i < m_size; i++)

View File

@ -1,8 +1,9 @@
#pragma once
#include <BAN/ForwardList.h>
#include <BAN/Formatter.h>
#include <BAN/ForwardList.h>
#include <BAN/Iterators.h>
#include <BAN/Optional.h>
namespace BAN
{
@ -35,6 +36,9 @@ namespace BAN
char back() const;
char front() const;
BAN::Optional<size_type> find(char) const;
BAN::Optional<size_type> find(bool(*comp)(char)) const;
bool contains(char) const;
size_type count(char) const;