31#ifndef ETL_STRING_VIEW_INCLUDED
32#define ETL_STRING_VIEW_INCLUDED
94 template <
typename T,
typename TTraits = etl::
char_traits<T> >
105 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
116 : mbegin(ETL_NULLPTR)
125 : mbegin(str.
begin())
161 : mbegin(
other.mbegin)
217 ETL_CONSTEXPR const_iterator cend()
const
225 ETL_CONSTEXPR const_reverse_iterator
rbegin()
const
227 return const_reverse_iterator(mend);
233 ETL_CONSTEXPR const_reverse_iterator
crbegin()
const
235 return const_reverse_iterator(mend);
241 ETL_CONSTEXPR const_reverse_iterator
rend()
const
243 return const_reverse_iterator(mbegin);
249 ETL_CONSTEXPR const_reverse_iterator
crend()
const
251 return const_reverse_iterator(mbegin);
263 return (mbegin == mend);
269 ETL_CONSTEXPR
size_t size()
const
271 return static_cast<size_t>(mend - mbegin);
295 mbegin =
other.mbegin;
341 using ETL_OR_STD::swap;
354 if (position <
size())
356 n = etl::min(count,
size() - position);
358 etl::copy(mbegin + position, mbegin + position +
n,
destination);
371 if (position <
size())
373 size_t n = etl::min(count,
size() - position);
402 return (*
this ==
view) ? 0 : ((*
this >
view) ? 1 : -1);
410 ETL_CONSTEXPR14
int compare(size_type position1, size_type count1,
412 size_type position2, size_type count2)
const
414 return substr(position1, count1).
compare(view.substr(position2, count2));
417 ETL_CONSTEXPR14
int compare(
const T* text)
const
422 ETL_CONSTEXPR14
int compare(size_type position, size_type count,
const T* text)
const
427 ETL_CONSTEXPR14
int compare(size_type position, size_type count1,
const T* text, size_type count2)
const
446 ETL_CONSTEXPR14
bool starts_with(
const T* text)
const
448 size_t lengthtext = TTraits::length(text);
450 return (
size() >= lengthtext) &&
451 (compare(0, lengthtext, text) == 0);
468 ETL_CONSTEXPR14
bool ends_with(
const T* text)
const
470 size_t lengthtext = TTraits::length(text);
471 size_t lengthview =
size();
473 return (lengthview >= lengthtext) &&
474 (compare(lengthview - lengthtext, lengthtext, text) == 0);
499 ETL_CONSTEXPR14 size_type
find(
T c, size_type position = 0)
const
504 ETL_CONSTEXPR14 size_type
find(
const T* text, size_type position, size_type count)
const
509 ETL_CONSTEXPR14 size_type
find(
const T* text, size_type position = 0)
const
524 position = etl::min(position,
size());
541 ETL_CONSTEXPR14 size_type
rfind(
T c, size_type position = npos)
const
546 ETL_CONSTEXPR14 size_type
rfind(
const T* text, size_type position, size_type count)
const
551 ETL_CONSTEXPR14 size_type
rfind(
const T* text, size_type position = npos)
const
582 ETL_CONSTEXPR14 size_type
find_first_of(
T c, size_type position = 0)
const
587 ETL_CONSTEXPR14 size_type
find_first_of(
const T* text, size_type position, size_type count)
const
592 ETL_CONSTEXPR14 size_type
find_first_of(
const T* text, size_type position = 0)
const
607 position = etl::min(position,
size() - 1);
609 const_reverse_iterator it =
rbegin() +
size() - position - 1;
617 if (mbegin[position] ==
view[
j])
630 ETL_CONSTEXPR14 size_type
find_last_of(
T c, size_type position = npos)
const
635 ETL_CONSTEXPR14 size_type
find_last_of(
const T* text, size_type position, size_type count)
const
640 ETL_CONSTEXPR14 size_type
find_last_of(
const T* text, size_type position = npos)
const
684 ETL_CONSTEXPR14 size_type
find_first_not_of(
const T* text, size_type position, size_type count)
const
689 ETL_CONSTEXPR14 size_type
find_first_not_of(
const T* text, size_type position = 0)
const
704 position = etl::min(position,
size() - 1);
706 const_reverse_iterator it =
rbegin() +
size() - position - 1;
716 if (mbegin[position] ==
view[
j])
740 ETL_CONSTEXPR14 size_type
find_last_not_of(
const T* text, size_type position, size_type count)
const
745 ETL_CONSTEXPR14 size_type
find_last_not_of(
const T* text, size_type position = npos)
const
755 return (
lhs.size() ==
rhs.size()) &&
756 etl::equal(
lhs.begin(),
lhs.end(),
rhs.begin());
772 return etl::lexicographical_compare(
lhs.begin(),
lhs.end(),
rhs.begin(),
rhs.end());
801 const_pointer mbegin;
814 template<
size_t Array_Size>
823 template<
size_t Array_Size>
824 ETL_CONSTEXPR14 wstring_view
make_string_view(
const wchar_t(&text)[Array_Size])
828 return wstring_view(text, length);
832 template<
size_t Array_Size>
833 ETL_CONSTEXPR14 u8string_view
make_string_view(
const char8_t(&text)[Array_Size])
837 return u8string_view(text, length);
841 template<
size_t Array_Size>
842 ETL_CONSTEXPR14 u16string_view
make_string_view(
const char16_t(&text)[Array_Size])
846 return u16string_view(text, length);
850 template<
size_t Array_Size>
851 ETL_CONSTEXPR14 u32string_view
make_string_view(
const char32_t(&text)[Array_Size])
855 return u32string_view(text, length);
861#if ETL_USING_8BIT_TYPES
863 struct hash<
etl::string_view>
867 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(text.data()),
868 reinterpret_cast<const uint8_t*
>(text.data() + text.size()));
873 struct hash<
etl::wstring_view>
877 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(text.data()),
878 reinterpret_cast<const uint8_t*
>(text.data() + text.size()));
883 struct hash<
etl::u16string_view>
887 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(text.data()),
888 reinterpret_cast<const uint8_t*
>(text.data() + text.size()));
893 struct hash<
etl::u32string_view>
897 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(text.data()),
898 reinterpret_cast<const uint8_t*
>(text.data() + text.size()));
907template <
typename T,
typename TTraits >
String view.
Definition string_view.h:96
ETL_CONSTEXPR14 int compare(basic_string_view< T, TTraits > view) const
Compares two views.
Definition string_view.h:400
ETL_CONSTEXPR14 void assign(const_pointer begin_, size_t size_)
Assign from iterator and size.
Definition string_view.h:312
ETL_CONSTEXPR basic_string_view() ETL_NOEXCEPT
Default constructor.
Definition string_view.h:115
ETL_CONSTEXPR14 bool ends_with(etl::basic_string_view< T, TTraits > view) const
Checks if the string view ends with the given suffix.
Definition string_view.h:457
ETL_CONSTEXPR14 size_type copy(T *destination, size_type count, size_type position=0) const
Copies characters.
Definition string_view.h:350
ETL_CONSTEXPR basic_string_view(const basic_string_view &other) ETL_NOEXCEPT
Copy constructor.
Definition string_view.h:160
friend ETL_CONSTEXPR14 bool operator<=(const etl::basic_string_view< T, TTraits > &lhs, const etl::basic_string_view< T, TTraits > &rhs)
Less-than-equal for string_view.
Definition string_view.h:786
ETL_CONSTEXPR const_reverse_iterator rend() const
Returns a const reverse iterator to the end of the array.
Definition string_view.h:241
ETL_CONSTEXPR const_reverse_iterator crbegin() const
Returns a const reverse iterator to the reverse beginning of the array.
Definition string_view.h:233
ETL_CONSTEXPR const_reverse_iterator crend() const
Returns a const reverse iterator to the end of the array.
Definition string_view.h:249
ETL_CONSTEXPR size_t max_size() const
Returns the maximum possible size of the array.
Definition string_view.h:285
ETL_CONSTEXPR14 void remove_suffix(size_type n)
Shrinks the view by moving its end backward.
Definition string_view.h:392
ETL_CONSTEXPR basic_string_view(const etl::ibasic_string< T > &str)
Construct from string.
Definition string_view.h:124
friend ETL_CONSTEXPR14 bool operator>=(const etl::basic_string_view< T, TTraits > &lhs, const etl::basic_string_view< T, TTraits > &rhs)
Greater-than-equal for string_view.
Definition string_view.h:794
ETL_CONSTEXPR14 bool starts_with(etl::basic_string_view< T, TTraits > view) const
Checks if the string view starts with the given prefix.
Definition string_view.h:435
ETL_CONSTEXPR basic_string_view(const T *begin_, const T *end_)
Construct from pointer range.
Definition string_view.h:142
ETL_CONSTEXPR14 size_type find_last_of(etl::basic_string_view< T, TTraits > view, size_type position=npos) const
Find last occurrence of characters.
Definition string_view.h:600
ETL_CONSTEXPR const_iterator begin() const
Returns a const iterator to the beginning of the array.
Definition string_view.h:193
friend ETL_CONSTEXPR14 bool operator!=(const etl::basic_string_view< T, TTraits > &lhs, const etl::basic_string_view< T, TTraits > &rhs)
Inequality for string_view.
Definition string_view.h:762
ETL_CONSTEXPR14 ETL_EXPLICIT_STRING_FROM_CHAR basic_string_view(const T *begin_)
Construct from T*.
Definition string_view.h:133
ETL_CONSTEXPR14 etl::basic_string_view< T, TTraits > & operator=(const etl::basic_string_view< T, TTraits > &other)
Assign from a view.
Definition string_view.h:293
ETL_CONSTEXPR14 void remove_prefix(size_type n)
Shrinks the view by moving its start forward.
Definition string_view.h:384
ETL_CONSTEXPR14 void assign(const_pointer begin_, const_pointer end_)
Assign from iterators.
Definition string_view.h:303
ETL_CONSTEXPR14 void swap(basic_string_view &other) ETL_NOEXCEPT
Swaps with another basic_string_view.
Definition string_view.h:339
ETL_CONSTEXPR const_pointer data() const
Returns a const pointer to the first element of the internal storage.
Definition string_view.h:185
ETL_CONSTEXPR size_t length() const
Returns the size of the array.
Definition string_view.h:277
ETL_CONSTEXPR const_reverse_iterator rbegin() const
Returns a const reverse iterator to the reverse beginning of the array.
Definition string_view.h:225
friend ETL_CONSTEXPR14 bool operator<(const etl::basic_string_view< T, TTraits > &lhs, const etl::basic_string_view< T, TTraits > &rhs)
Less-than for string_view.
Definition string_view.h:770
ETL_CONSTEXPR const_reference back() const
Returns a const reference to the last element.
Definition string_view.h:177
ETL_CONSTEXPR14 size_type find_last_not_of(etl::basic_string_view< T, TTraits > view, size_type position=npos) const
Find last absence of characters.
Definition string_view.h:697
ETL_CONSTEXPR14 size_type find_first_of(etl::basic_string_view< T, TTraits > view, size_type position=0) const
Find first occurrence of characters.
Definition string_view.h:559
const_reference at(size_t i) const
Returns a const reference to the indexed value.
Definition string_view.h:329
ETL_CONSTEXPR bool empty() const
Returns true if the array size is zero.
Definition string_view.h:261
ETL_CONSTEXPR14 size_type find(etl::basic_string_view< T, TTraits > view, size_type position=0) const
Find characters in the view.
Definition string_view.h:480
ETL_CONSTEXPR14 size_type rfind(etl::basic_string_view< T, TTraits > view, size_type position=npos) const
Find the last occurrence of a substring.
Definition string_view.h:517
ETL_CONSTEXPR const_iterator cbegin() const
Returns a const iterator to the beginning of the array.
Definition string_view.h:201
friend ETL_CONSTEXPR14 bool operator>(const etl::basic_string_view< T, TTraits > &lhs, const etl::basic_string_view< T, TTraits > &rhs)
Greater-than for string_view.
Definition string_view.h:778
ETL_CONSTEXPR14 basic_string_view substr(size_type position=0, size_type count=npos) const
Returns a substring.
Definition string_view.h:367
friend ETL_CONSTEXPR14 bool operator==(const etl::basic_string_view< T, TTraits > &lhs, const etl::basic_string_view< T, TTraits > &rhs)
Equality for string_view.
Definition string_view.h:753
ETL_CONSTEXPR const_reference front() const
Returns a const reference to the first element.
Definition string_view.h:169
ETL_CONSTEXPR const_reference operator[](size_t i) const
Returns a const reference to the indexed value.
Definition string_view.h:321
ETL_CONSTEXPR14 size_type find_first_not_of(etl::basic_string_view< T, TTraits > view, size_type position=0) const
Find first absence of characters.
Definition string_view.h:648
ETL_CONSTEXPR const_iterator end() const
Returns a const iterator to the end of the array.
Definition string_view.h:209
ETL_CONSTEXPR basic_string_view(const T *begin_, size_t size_)
Construct from pointer/size.
Definition string_view.h:151
ETL_CONSTEXPR size_t size() const
Returns the size of the array.
Definition string_view.h:269
The base class for basic_string_view exceptions.
Definition string_view.h:54
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
Definition exception.h:47
Definition integral_limits.h:516
Definition string_view.h:68
Definition string_view.h:82
bitset_ext
Definition absolute.h:38
void swap(etl::array< T, SIZE > &lhs, etl::array< T, SIZE > &rhs)
Template deduction guides.
Definition array.h:630
ETL_CONSTEXPR14 string_view make_string_view(const char(&text)[Array_Size])
make_string_view.
Definition string_view.h:815
Character traits for any character type.
Definition char_traits.h:120
pair holds two objects of arbitrary type
Definition utility.h:164