2022-12-13 20:41:32 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-01-17 11:21:21 +02:00
|
|
|
#include <BAN/ForwardList.h>
|
2022-12-13 20:41:32 +02:00
|
|
|
#include <BAN/Formatter.h>
|
2023-03-20 13:26:42 +02:00
|
|
|
#include <BAN/Iterators.h>
|
2022-12-13 20:41:32 +02:00
|
|
|
|
|
|
|
namespace BAN
|
|
|
|
{
|
|
|
|
|
|
|
|
class StringView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using size_type = size_t;
|
2023-03-20 13:26:42 +02:00
|
|
|
using const_iterator = ConstIteratorSimple<char, StringView>;
|
2022-12-13 20:41:32 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
StringView();
|
|
|
|
StringView(const String&);
|
|
|
|
StringView(const char*, size_type = -1);
|
|
|
|
|
2023-03-20 13:26:42 +02:00
|
|
|
const_iterator begin() const { return const_iterator(m_data); }
|
|
|
|
const_iterator end() const { return const_iterator(m_data + m_size); }
|
|
|
|
|
2022-12-13 20:41:32 +02:00
|
|
|
char operator[](size_type) const;
|
|
|
|
|
2022-12-13 20:55:09 +02:00
|
|
|
bool operator==(const String&) const;
|
|
|
|
bool operator==(StringView) const;
|
|
|
|
bool operator==(const char*) const;
|
2022-12-13 20:41:32 +02:00
|
|
|
|
2023-02-01 21:05:44 +02:00
|
|
|
StringView substring(size_type, size_type = -1) const;
|
2022-12-13 20:41:32 +02:00
|
|
|
|
2023-02-19 20:10:30 +02:00
|
|
|
ErrorOr<Vector<StringView>> split(char, bool = false);
|
|
|
|
ErrorOr<Vector<StringView>> split(bool(*comp)(char), bool = false);
|
2022-12-13 20:41:32 +02:00
|
|
|
|
2023-02-01 21:05:44 +02:00
|
|
|
char back() const;
|
|
|
|
char front() const;
|
2023-01-16 18:56:51 +02:00
|
|
|
|
2023-06-05 22:46:37 +03:00
|
|
|
bool contains(char) const;
|
2023-02-01 21:05:44 +02:00
|
|
|
size_type count(char) const;
|
2022-12-13 20:41:32 +02:00
|
|
|
|
2023-02-01 21:05:44 +02:00
|
|
|
bool empty() const;
|
|
|
|
size_type size() const;
|
2022-12-13 20:41:32 +02:00
|
|
|
|
2023-02-01 21:05:44 +02:00
|
|
|
const char* data() const;
|
2022-12-13 20:41:32 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
const char* m_data = nullptr;
|
|
|
|
size_type m_size = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-16 12:15:16 +02:00
|
|
|
inline BAN::StringView operator""sv(const char* str, BAN::StringView::size_type len) { return BAN::StringView(str, len); }
|
2023-01-12 23:57:07 +02:00
|
|
|
|
2022-12-13 20:41:32 +02:00
|
|
|
namespace BAN::Formatter
|
|
|
|
{
|
|
|
|
|
2022-12-27 19:55:07 +02:00
|
|
|
template<typename F>
|
2023-03-08 21:31:26 +02:00
|
|
|
void print_argument(F putc, const StringView& sv, const ValueFormat&)
|
2022-12-13 20:41:32 +02:00
|
|
|
{
|
2023-02-01 21:05:44 +02:00
|
|
|
for (StringView::size_type i = 0; i < sv.size(); i++)
|
2022-12-27 19:55:07 +02:00
|
|
|
putc(sv[i]);
|
2022-12-13 20:41:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|