2#ifndef TETL_BASIC_STRING_VIEW_STRING_VIEW_HPP
3#define TETL_BASIC_STRING_VIEW_STRING_VIEW_HPP
33template <
typename Char,
typename Traits = etl::
char_traits<Char>>
86 template <
typename Iter>
87 requires(detail::RandomAccessIterator<Iter>)
149 return unsafe_at(pos);
165 return unsafe_at(_size - 1);
184 [[nodiscard]]
constexpr auto empty() const noexcept ->
bool {
return _size == 0; }
217 traits_type::copy(dest,
data() + pos, rcount);
236 auto const res = traits_type::compare(
data(), v.data(), rlen);
245 if (
size() < v.size()) {
248 if (
size() > v.size()) {
258 return substr(pos1, count1).compare(v);
262 [[nodiscard]]
constexpr auto
265 return substr(pos1, count1).compare(v.substr(pos2, count2));
288 return substr(0, sv.size()) == sv;
294 [[nodiscard]]
constexpr auto starts_with(Char c)
const noexcept ->
bool
296 return !
empty() && traits_type::eq(
front(), c);
303 [[nodiscard]]
constexpr auto starts_with(Char
const* str)
const ->
bool
322 [[nodiscard]]
constexpr auto ends_with(Char c)
const noexcept ->
bool {
return !
empty() && Traits::eq(
back(), c); }
341 for (
size_type outerIdx = pos; outerIdx <
size(); ++outerIdx) {
342 if (unsafe_at(outerIdx) == v.
front()) {
344 for (
size_type innerIdx = 0; innerIdx < v.
size(); ++innerIdx) {
345 auto offset = outerIdx + innerIdx;
346 if (unsafe_at(offset) != v[innerIdx]) {
398 if (sv.size() <
size() - pos) {
405 if (sv.size() > 0 && r ==
data() + pos) {
427 for (
auto const* s =
data() + pos; s !=
data();) {
428 if (Traits::eq(*--s, c)) {
452 return rfind({s, traits_type::length(s)}, pos);
464 for (
auto const c : v) {
465 if (c == unsafe_at(idx)) {
514 auto const* str =
data();
516 auto const* last = str +
size();
517 for (
auto const* s = str + pos; s != last; ++s) {
518 if (Traits::find(sv.
data(), sv.
size(), *s) ==
nullptr) {
535 for (
auto const* s =
data() + pos; s != last; ++s) {
536 if (!Traits::eq(*s, c)) {
576 auto const current = unsafe_at(offset);
577 for (
auto const ch : v) {
582 }
while (offset-- != 0);
635 auto equals = [&](
auto ch) {
return ch == unsafe_at(offset); };
639 }
while (offset-- != 0);
681 [[nodiscard]]
constexpr auto contains(Char c)
const noexcept ->
bool {
return find(c) !=
npos; }
684 [[nodiscard]]
constexpr auto contains(Char
const* s)
const ->
bool {
return find(s) !=
npos; }
760template <
typename Char,
typename Traits>
771template <
typename Char,
typename Traits>
772[[nodiscard]]
constexpr auto
775 if (lhs.size() != rhs.size()) {
778 return lhs.compare(rhs) == 0;
787template <
typename Char,
typename Traits>
788[[nodiscard]]
constexpr auto
794template <
typename Char,
typename Traits,
int = 1>
795[[nodiscard]]
constexpr auto
801template <
typename Char,
typename Traits,
int = 2>
802[[nodiscard]]
constexpr auto
814template <
typename Char,
typename Traits>
815[[nodiscard]]
constexpr auto
818 return (lhs < rhs) or (lhs == rhs);
821template <
typename Char,
typename Traits,
int = 1>
822[[nodiscard]]
constexpr auto
825 return (lhs < rhs) or (lhs == rhs);
828template <
typename Char,
typename Traits,
int = 2>
829[[nodiscard]]
constexpr auto
832 return (lhs < rhs) or (lhs == rhs);
841template <
typename Char,
typename Traits>
842[[nodiscard]]
constexpr auto
845 return !(lhs < rhs) and !(lhs == rhs);
848template <
typename Char,
typename Traits,
int = 1>
849[[nodiscard]]
constexpr auto
852 return !(lhs < rhs) and !(lhs == rhs);
855template <
typename Char,
typename Traits,
int = 2>
856[[nodiscard]]
constexpr auto
859 return !(lhs < rhs) and !(lhs == rhs);
868template <
typename Char,
typename Traits>
869[[nodiscard]]
constexpr auto
872 return lhs > rhs or lhs == rhs;
875template <
typename Char,
typename Traits,
int = 1>
876[[nodiscard]]
constexpr auto
879 return lhs > rhs or lhs == rhs;
882template <
typename Char,
typename Traits,
int = 2>
883[[nodiscard]]
constexpr auto
886 return lhs > rhs or lhs == rhs;
#define TETL_PRECONDITION(...)
Definition check.hpp:16
constexpr auto clamp(Type const &v, Type const &lo, Type const &hi, Compare comp) -> Type const &
If v compares less than lo, returns lo; otherwise if hi compares less than v, returns hi; otherwise r...
Definition clamp.hpp:17
constexpr auto min(Type const &a, Type const &b, Compare comp) noexcept -> Type const &
Returns the smaller of a and b, using a compare function.
Definition min.hpp:13
constexpr auto none_of(InputIt first, InputIt last, Predicate p) -> bool
Checks if unary predicate p returns true for no elements in the range [first, last).
Definition none_of.hpp:13
constexpr auto find_end(ForwardIt1 first, ForwardIt1 last, ForwardIt2 sFirst, ForwardIt2 sLast, Predicate p) -> ForwardIt1
Searches for the last occurrence of the sequence [sFirst, sLast) in the range [first,...
Definition find_end.hpp:25
constexpr auto lexicographical_compare(InputIt1 f1, InputIt1 l1, InputIt2 f2, InputIt2 l2, Compare comp) -> bool
Checks if the first range [f1, l1) is lexicographically less than the second range [f2,...
Definition lexicographical_compare.hpp:17
constexpr auto count(InputIt first, InputIt last, T const &value) -> typename iterator_traits< InputIt >::difference_type
Returns the number of elements in the range [first, last) satisfying specific criteria....
Definition count.hpp:21
constexpr auto size(C const &c) noexcept(noexcept(c.size())) -> decltype(c.size())
Returns the size of the given container c or array array. Returns c.size(), converted to the return t...
Definition size.hpp:18
constexpr bool enable_borrowed_range
Definition enable_borrowed_range.hpp:10
basic_string_view< char32_t, etl::char_traits< char32_t > > u32string_view
Typedef for common character type char32_t
Definition basic_string_view.hpp:720
basic_string_view< char, etl::char_traits< char > > string_view
Typedef for common character type char
Definition basic_string_view.hpp:704
basic_string_view< char16_t, etl::char_traits< char16_t > > u16string_view
Typedef for common character type char16_t
Definition basic_string_view.hpp:716
basic_string_view< wchar_t, etl::char_traits< wchar_t > > wstring_view
Typedef for common character type wchar_t
Definition basic_string_view.hpp:708
basic_string_view< char8_t, etl::char_traits< char8_t > > u8string_view
Typedef for common character type char8_t
Definition basic_string_view.hpp:712
typename type_identity< T >::type type_identity_t
Definition type_identity.hpp:16
Definition basic_string_view.hpp:723
Definition ranges_in_fun_result.hpp:11
Definition adjacent_find.hpp:8
constexpr auto operator==(inplace_function< R(Args...), Capacity, Alignment > const &f, nullptr_t) noexcept -> bool
Compares a etl::inplace_function with a null pointer. Empty functions (that is, functions without a c...
Definition inplace_function.hpp:262
constexpr auto operator<(etl::reverse_iterator< Iter1 > const &lhs, etl::reverse_iterator< Iter2 > const &rhs) -> bool
Compares the underlying iterators. Inverse comparisons are applied in order to take into account that...
Definition reverse_iterator.hpp:167
TETL_BUILTIN_PTRDIFF ptrdiff_t
etl::ptrdiff_t is the signed integer type of the result of subtracting two pointers.
Definition ptrdiff_t.hpp:14
constexpr auto operator<=(etl::reverse_iterator< Iter1 > const &lhs, etl::reverse_iterator< Iter2 > const &rhs) -> bool
Compares the underlying iterators. Inverse comparisons are applied in order to take into account that...
Definition reverse_iterator.hpp:177
auto swap(inplace_function< R(Args...), Capacity, Alignment > &lhs, inplace_function< R(Args...), Capacity, Alignment > &rhs) noexcept -> void
Overloads the etl::swap algorithm for etl::inplace_function. Exchanges the state of lhs with that of ...
Definition inplace_function.hpp:249
constexpr auto operator>(etl::reverse_iterator< Iter1 > const &lhs, etl::reverse_iterator< Iter2 > const &rhs) -> bool
Compares the underlying iterators. Inverse comparisons are applied in order to take into account that...
Definition reverse_iterator.hpp:185
constexpr auto operator>=(etl::reverse_iterator< Iter1 > const &lhs, etl::reverse_iterator< Iter2 > const &rhs) -> bool
Compares the underlying iterators. Inverse comparisons are applied in order to take into account that...
Definition reverse_iterator.hpp:195
TETL_BUILTIN_SIZET size_t
etl::size_t is the unsigned integer type of the result of the sizeof operator.
Definition size_t.hpp:14
decltype(nullptr) nullptr_t
etl::nullptr_t is the type of the null pointer literal, nullptr. It is a distinct type that is not it...
Definition nullptr_t.hpp:13
The class template basic_string_view describes an object that can refer to a constant contiguous sequ...
Definition basic_string_view.hpp:34
constexpr auto compare(size_type pos1, size_type count1, Char const *s) const -> int
Compares two character sequences. Equivalent to substr(pos1, count1).compare(basic_string_view(s)).
Definition basic_string_view.hpp:272
CharT * pointer
Definition basic_string_view.hpp:37
constexpr auto compare(size_type pos1, size_type count1, Char const *s, size_type count2) const -> int
Compares two character sequences. Equivalent to substr(pos1, count1).compare(basic_string_view(s,...
Definition basic_string_view.hpp:278
constexpr auto ends_with(Char const *str) const -> bool
Checks if the string view ends with the given suffix, where the the prefix is a null-terminated chara...
Definition basic_string_view.hpp:328
const_reverse_iterator reverse_iterator
Definition basic_string_view.hpp:46
constexpr auto rfind(Char const *s, size_type pos=npos) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Equivalent to rfind(basic_string_view...
Definition basic_string_view.hpp:450
constexpr auto back() const -> const_reference
Returns reference to the last character in the view.
Definition basic_string_view.hpp:162
constexpr auto compare(Char const *s) const -> int
Compares two character sequences. Equivalent to compare(basic_string_view(s)).
Definition basic_string_view.hpp:269
constexpr auto find_first_of(Char const *s, size_type pos=0) const -> size_type
Finds the first character equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:502
static constexpr size_type npos
Definition basic_string_view.hpp:693
etl::ptrdiff_t difference_type
Definition basic_string_view.hpp:44
constexpr auto find_first_not_of(basic_string_view sv, size_type pos=0) const noexcept -> size_type
Finds the first character not equal to any of the characters in the given character sequence.
Definition basic_string_view.hpp:512
constexpr auto rfind(basic_string_view sv, size_type pos=npos) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Finds the last occurence of v in this...
Definition basic_string_view.hpp:395
~basic_string_view() noexcept=default
etl::size_t size_type
Definition basic_string_view.hpp:43
constexpr auto crbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first character of the reversed view. It corresponds to the last ch...
Definition basic_string_view.hpp:120
constexpr auto rfind(Char const *s, size_type pos, size_type count) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Equivalent to rfind(basic_string_view...
Definition basic_string_view.hpp:440
etl::reverse_iterator< const_iterator > const_reverse_iterator
Definition basic_string_view.hpp:45
CharT const & const_reference
Definition basic_string_view.hpp:40
constexpr auto starts_with(Char const *str) const -> bool
Checks if the string view begins with the given prefix, where the the prefix is a null-terminated cha...
Definition basic_string_view.hpp:303
constexpr auto find(Char const *s, size_type pos=0) const -> size_type
Finds the first substring equal to the given character sequence. Equivalent to find(basic_string_view...
Definition basic_string_view.hpp:388
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first character of the reversed view. It corresponds to the last ch...
Definition basic_string_view.hpp:116
constexpr auto copy(Char *dest, size_type count, size_type pos=0) const -> size_type
Copies the substring [pos, pos + rcount) to the character array pointed to by dest,...
Definition basic_string_view.hpp:213
constexpr auto find_last_of(Char const *s, size_type pos, size_type count) const -> size_type
Finds the last character equal to one of characters in the given character sequence....
Definition basic_string_view.hpp:608
constexpr auto find(Char ch, size_type pos=0) const noexcept -> size_type
Finds the first substring equal to the given character sequence. Equivalent to find(basic_string_view...
Definition basic_string_view.hpp:368
constexpr auto compare(size_type pos1, size_type count1, basic_string_view v) const -> int
Compares two character sequences. Equivalent to substr(pos1, count1).compare(v).
Definition basic_string_view.hpp:256
constexpr auto find(basic_string_view v, size_type pos=0) const noexcept -> size_type
Finds the first substring equal to the given character sequence. Finds the first occurence of v in th...
Definition basic_string_view.hpp:335
constexpr auto find_last_of(Char const *s, size_type pos=npos) const -> size_type
Finds the last character equal to one of characters in the given character sequence....
Definition basic_string_view.hpp:621
constexpr auto find_first_not_of(Char const *s, size_type pos, size_type count) const -> size_type
Finds the first character not equal to any of the characters in the given character sequence.
Definition basic_string_view.hpp:549
constexpr auto find_last_not_of(const_pointer s, size_type pos=npos) const -> size_type
Finds the last character not equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:672
constexpr auto find_last_not_of(Char c, size_type pos=npos) const noexcept -> size_type
Finds the last character not equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:650
constexpr auto contains(basic_string_view sv) const noexcept -> bool
Checks if the string contains the given substring.
Definition basic_string_view.hpp:678
constexpr auto rfind(Char c, size_type pos=npos) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Equivalent to rfind(basic_string_view...
Definition basic_string_view.hpp:416
constexpr auto find_last_not_of(const_pointer s, size_type pos, size_type count) const -> size_type
Finds the last character not equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:661
constexpr auto ends_with(Char c) const noexcept -> bool
Checks if the string view ends with the given suffix, where the prefix is a single character.
Definition basic_string_view.hpp:322
constexpr basic_string_view(nullptr_t)=delete
constexpr basic_string_view() noexcept=default
Default constructor. Constructs an empty basic_string_view. After construction, data() is equal to nu...
etl::char_traits< CharT > traits_type
Definition basic_string_view.hpp:35
constexpr auto compare(basic_string_view v) const noexcept -> int
Compares two character sequences.
Definition basic_string_view.hpp:233
constexpr auto begin() const noexcept -> const_iterator
Definition basic_string_view.hpp:99
constexpr auto cbegin() const noexcept -> const_iterator
Returns an iterator to the first character of the view.
Definition basic_string_view.hpp:102
constexpr auto contains(Char c) const noexcept -> bool
Checks if the string contains the given substring.
Definition basic_string_view.hpp:681
CharT const * const_pointer
Definition basic_string_view.hpp:38
constexpr basic_string_view(Iter first, Iter last)
Constructs a basic_string_view over the range [first, last). The behavior is undefined if [first,...
Definition basic_string_view.hpp:88
constexpr auto contains(Char const *s) const -> bool
Checks if the string contains the given substring.
Definition basic_string_view.hpp:684
constexpr auto front() const -> const_reference
Returns reference to the first character in the view.
Definition basic_string_view.hpp:154
constexpr auto empty() const noexcept -> bool
Checks if the view has no characters, i.e. whether size() == 0.
Definition basic_string_view.hpp:184
constexpr auto compare(size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const -> int
Compares two character sequences. Equivalent to substr(pos1, count1).compare(v.substr(pos2,...
Definition basic_string_view.hpp:263
constexpr auto starts_with(basic_string_view sv) const noexcept -> bool
Checks if the string view begins with the given prefix, where the prefix is a string view.
Definition basic_string_view.hpp:286
CharT & reference
Definition basic_string_view.hpp:39
constexpr auto substr(size_type pos=0, size_type count=npos) const -> basic_string_view
Returns a view of the substring [pos, pos + rcount), where rcount is the smaller of count and size() ...
Definition basic_string_view.hpp:223
constexpr auto remove_suffix(size_type n) -> void
Moves the end of the view back by n characters.
Definition basic_string_view.hpp:197
constexpr auto find_last_of(Char c, size_type pos=npos) const noexcept -> size_type
Finds the last character equal to one of characters in the given character sequence....
Definition basic_string_view.hpp:595
constexpr auto find(Char const *s, size_type pos, size_type count) const -> size_type
Finds the first substring equal to the given character sequence. Equivalent to find(basic_string_view...
Definition basic_string_view.hpp:378
constexpr auto find_last_of(basic_string_view v, size_type pos=npos) const noexcept -> size_type
Finds the last character equal to one of characters in the given character sequence....
Definition basic_string_view.hpp:572
constexpr auto length() const noexcept -> size_type
Definition basic_string_view.hpp:177
constexpr auto find_first_of(Char const *s, size_type pos, size_type count) const -> size_type
Finds the first character equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:491
CharT const * const_iterator
Definition basic_string_view.hpp:41
const_iterator iterator
Definition basic_string_view.hpp:42
constexpr auto swap(basic_string_view &v) noexcept -> void
Exchanges the view with that of v.
Definition basic_string_view.hpp:204
constexpr auto max_size() const noexcept -> size_type
The largest possible number of char-like objects that can be referred to by a basic_string_view.
Definition basic_string_view.hpp:181
constexpr basic_string_view(Char const *str)
Constructs a view of the null-terminated character string pointed to by s, not including the terminat...
Definition basic_string_view.hpp:74
constexpr auto end() const noexcept -> const_iterator
Returns an iterator to the character following the last character of the view. This character acts as...
Definition basic_string_view.hpp:107
constexpr auto remove_prefix(size_type n) -> void
Moves the start of the view forward by n characters.
Definition basic_string_view.hpp:188
constexpr auto starts_with(Char c) const noexcept -> bool
Checks if the string view begins with the given prefix, where the prefix is a single character.
Definition basic_string_view.hpp:294
constexpr auto operator[](size_type pos) const -> const_reference
Returns a const reference to the character at specified location pos.
Definition basic_string_view.hpp:146
constexpr auto find_first_not_of(Char const *s, size_type pos=0) const -> size_type
Finds the first character not equal to any of the characters in the given character sequence.
Definition basic_string_view.hpp:559
constexpr auto find_last_not_of(basic_string_view v, size_type pos=npos) const noexcept -> size_type
Finds the last character not equal to any of the characters of v in this view, starting at position p...
Definition basic_string_view.hpp:631
constexpr auto find_first_of(Char c, size_type pos=0) const noexcept -> size_type
Finds the first character equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:480
constexpr auto crend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the character following the last character of the reversed view.
Definition basic_string_view.hpp:139
constexpr auto ends_with(basic_string_view sv) const noexcept -> bool
Checks if the string view ends with the given suffix, where the prefix is a string view.
Definition basic_string_view.hpp:313
constexpr auto find_first_of(basic_string_view v, size_type pos=0) const noexcept -> size_type
Finds the first character equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:461
constexpr auto data() const noexcept -> const_pointer
Returns a pointer to the underlying character array. The pointer is such that the range [data(); data...
Definition basic_string_view.hpp:171
constexpr auto rend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the character following the last character of the reversed view.
Definition basic_string_view.hpp:131
CharT value_type
Definition basic_string_view.hpp:36
constexpr auto size() const noexcept -> size_type
Definition basic_string_view.hpp:174
constexpr auto cend() const noexcept -> const_iterator
Returns an iterator to the character following the last character of the view. This character acts as...
Definition basic_string_view.hpp:112
constexpr auto find_first_not_of(Char c, size_type pos=0) const noexcept -> size_type
Finds the first character not equal to any of the characters in the given character sequence.
Definition basic_string_view.hpp:531
reverse_iterator is an iterator adaptor that reverses the direction of a given iterator....
Definition reverse_iterator.hpp:22