#pragma once #include #include #include #include namespace BAN { class StringView { public: using size_type = size_t; using const_iterator = ConstIteratorSimple; public: StringView(); StringView(const String&); StringView(const char*, size_type = -1); const_iterator begin() const { return const_iterator(m_data); } const_iterator end() const { return const_iterator(m_data + m_size); } char operator[](size_type) const; bool operator==(const String&) const; bool operator==(StringView) const; bool operator==(const char*) const; StringView substring(size_type, size_type = -1) const; ErrorOr> split(char, bool = false) const; ErrorOr> split(bool(*comp)(char), bool = false) const; char back() const; char front() const; BAN::Optional find(char) const; BAN::Optional find(bool(*comp)(char)) const; bool contains(char) const; size_type count(char) const; bool empty() const; size_type size() const; const char* data() const; private: const char* m_data = nullptr; size_type m_size = 0; }; } inline BAN::StringView operator""sv(const char* str, BAN::StringView::size_type len) { return BAN::StringView(str, len); } namespace BAN::Formatter { template void print_argument(F putc, const StringView& sv, const ValueFormat&) { for (StringView::size_type i = 0; i < sv.size(); i++) putc(sv[i]); } }