31#ifndef ETL_STRING_VIEW_INCLUDED
32#define ETL_STRING_VIEW_INCLUDED
46#if ETL_USING_STL && ETL_USING_CPP17
47 #include <string_view>
98 template <
typename T,
typename TTraits = etl::
char_traits<T> >
109 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
120 : mbegin(ETL_NULLPTR)
129 : mbegin(str.
begin())
165 : mbegin(
other.mbegin)
221 ETL_CONSTEXPR const_iterator cend()
const
229 ETL_CONSTEXPR const_reverse_iterator
rbegin()
const
231 return const_reverse_iterator(mend);
237 ETL_CONSTEXPR const_reverse_iterator
crbegin()
const
239 return const_reverse_iterator(mend);
245 ETL_CONSTEXPR const_reverse_iterator
rend()
const
247 return const_reverse_iterator(mbegin);
253 ETL_CONSTEXPR const_reverse_iterator
crend()
const
255 return const_reverse_iterator(mbegin);
267 return (mbegin == mend);
273 ETL_CONSTEXPR
size_t size()
const
275 return static_cast<size_t>(mend - mbegin);
299 mbegin =
other.mbegin;
345 using ETL_OR_STD::swap;
358 if (position <
size())
360 n = etl::min(count,
size() - position);
362 etl::copy(mbegin + position, mbegin + position +
n,
destination);
375 if (position <
size())
377 size_t n = etl::min(count,
size() - position);
406 return (*
this ==
view) ? 0 : ((*
this >
view) ? 1 : -1);
414 ETL_CONSTEXPR14
int compare(size_type position1, size_type count1,
416 size_type position2, size_type count2)
const
418 return substr(position1, count1).
compare(view.substr(position2, count2));
421 ETL_CONSTEXPR14
int compare(
const T* text)
const
423 const T* view_itr = mbegin;
424 const T* text_itr = text;
426 while (view_itr != mend && *text_itr != T(0))
428 if (*view_itr < *text_itr)
432 else if (*view_itr > *text_itr)
440 if ((view_itr == mend) && (*text_itr == T(0)))
444 else if (view_itr == mend)
454 ETL_CONSTEXPR14
int compare(size_type position, size_type count,
const T* text)
const
459 ETL_CONSTEXPR14
int compare(size_type position, size_type count1,
const T* text, size_type count2)
const
478 ETL_CONSTEXPR14
bool starts_with(
const T* text)
const
480 size_t lengthtext = TTraits::length(text);
482 return (
size() >= lengthtext) &&
483 (compare(0, lengthtext, text) == 0);
500 ETL_CONSTEXPR14
bool ends_with(
const T* text)
const
502 size_t lengthtext = TTraits::length(text);
503 size_t lengthview =
size();
505 return (lengthview >= lengthtext) &&
506 (compare(lengthview - lengthtext, lengthtext, text) == 0);
531 ETL_CONSTEXPR14 size_type
find(
T c, size_type position = 0)
const
536 ETL_CONSTEXPR14 size_type
find(
const T* text, size_type position, size_type count)
const
541 ETL_CONSTEXPR14 size_type
find(
const T* text, size_type position = 0)
const
556 position = etl::min(position,
size());
573 ETL_CONSTEXPR14 size_type
rfind(
T c, size_type position = npos)
const
578 ETL_CONSTEXPR14 size_type
rfind(
const T* text, size_type position, size_type count)
const
583 ETL_CONSTEXPR14 size_type
rfind(
const T* text, size_type position = npos)
const
614 ETL_CONSTEXPR14 size_type
find_first_of(
T c, size_type position = 0)
const
619 ETL_CONSTEXPR14 size_type
find_first_of(
const T* text, size_type position, size_type count)
const
624 ETL_CONSTEXPR14 size_type
find_first_of(
const T* text, size_type position = 0)
const
639 position = etl::min(position,
size() - 1);
641 const_reverse_iterator it =
rbegin() +
size() - position - 1;
649 if (mbegin[position] ==
view[
j])
662 ETL_CONSTEXPR14 size_type
find_last_of(
T c, size_type position = npos)
const
667 ETL_CONSTEXPR14 size_type
find_last_of(
const T* text, size_type position, size_type count)
const
672 ETL_CONSTEXPR14 size_type
find_last_of(
const T* text, size_type position = npos)
const
716 ETL_CONSTEXPR14 size_type
find_first_not_of(
const T* text, size_type position, size_type count)
const
721 ETL_CONSTEXPR14 size_type
find_first_not_of(
const T* text, size_type position = 0)
const
736 position = etl::min(position,
size() - 1);
738 const_reverse_iterator it =
rbegin() +
size() - position - 1;
748 if (mbegin[position] ==
view[
j])
772 ETL_CONSTEXPR14 size_type
find_last_not_of(
const T* text, size_type position, size_type count)
const
777 ETL_CONSTEXPR14 size_type
find_last_not_of(
const T* text, size_type position = npos)
const
795 return find(
s) != npos;
803 return find(
c) != npos;
811 return (
lhs.size() ==
rhs.size()) &&
812 etl::equal(
lhs.begin(),
lhs.end(),
rhs.begin());
828 return etl::lexicographical_compare(
lhs.begin(),
lhs.end(),
rhs.begin(),
rhs.end());
857 const_pointer mbegin;
870 template<
size_t Array_Size>
879 template<
size_t Array_Size>
880 ETL_CONSTEXPR14 wstring_view
make_string_view(
const wchar_t(&text)[Array_Size])
884 return wstring_view(text, length);
888 template<
size_t Array_Size>
889 ETL_CONSTEXPR14 u8string_view
make_string_view(
const char8_t(&text)[Array_Size])
893 return u8string_view(text, length);
897 template<
size_t Array_Size>
898 ETL_CONSTEXPR14 u16string_view
make_string_view(
const char16_t(&text)[Array_Size])
902 return u16string_view(text, length);
906 template<
size_t Array_Size>
907 ETL_CONSTEXPR14 u32string_view
make_string_view(
const char32_t(&text)[Array_Size])
911 return u32string_view(text, length);
917#if ETL_USING_8BIT_TYPES
919 struct hash<
etl::string_view>
923 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(text.
data()),
924 reinterpret_cast<const uint8_t*
>(text.
data() + text.
size()));
929 struct hash<
etl::wstring_view>
933 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(text.
data()),
934 reinterpret_cast<const uint8_t*
>(text.
data() + text.
size()));
939 struct hash<
etl::u16string_view>
943 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(text.
data()),
944 reinterpret_cast<const uint8_t*
>(text.
data() + text.
size()));
949 struct hash<
etl::u32string_view>
953 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(text.
data()),
954 reinterpret_cast<const uint8_t*
>(text.
data() + text.
size()));
963template <
typename T,
typename TTraits >
String view.
Definition string_view.h:100
ETL_CONSTEXPR14 int compare(basic_string_view< T, TTraits > view) const
Compares two views.
Definition string_view.h:404
ETL_CONSTEXPR14 void assign(const_pointer begin_, size_t size_)
Assign from iterator and size.
Definition string_view.h:316
ETL_CONSTEXPR basic_string_view() ETL_NOEXCEPT
Default constructor.
Definition string_view.h:119
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:489
ETL_CONSTEXPR14 size_type copy(T *destination, size_type count, size_type position=0) const
Copies characters.
Definition string_view.h:354
ETL_CONSTEXPR basic_string_view(const basic_string_view &other) ETL_NOEXCEPT
Copy constructor.
Definition string_view.h:164
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:842
ETL_CONSTEXPR const_reverse_iterator rend() const
Returns a const reverse iterator to the end of the array.
Definition string_view.h:245
ETL_CONSTEXPR const_reverse_iterator crbegin() const
Returns a const reverse iterator to the reverse beginning of the array.
Definition string_view.h:237
ETL_CONSTEXPR const_reverse_iterator crend() const
Returns a const reverse iterator to the end of the array.
Definition string_view.h:253
ETL_CONSTEXPR size_t max_size() const
Returns the maximum possible size of the array.
Definition string_view.h:289
ETL_CONSTEXPR14 void remove_suffix(size_type n)
Shrinks the view by moving its end backward.
Definition string_view.h:396
ETL_CONSTEXPR basic_string_view(const etl::ibasic_string< T > &str)
Construct from string.
Definition string_view.h:128
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:850
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:467
ETL_CONSTEXPR basic_string_view(const T *begin_, const T *end_)
Construct from pointer range.
Definition string_view.h:146
bool contains(value_type c) const
Checks that character is within this string.
Definition string_view.h:801
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:632
ETL_CONSTEXPR const_iterator begin() const
Returns a const iterator to the beginning of the array.
Definition string_view.h:197
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:818
ETL_CONSTEXPR14 ETL_EXPLICIT_STRING_FROM_CHAR basic_string_view(const T *begin_)
Construct from T*.
Definition string_view.h:137
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:297
ETL_CONSTEXPR14 void remove_prefix(size_type n)
Shrinks the view by moving its start forward.
Definition string_view.h:388
ETL_CONSTEXPR14 void assign(const_pointer begin_, const_pointer end_)
Assign from iterators.
Definition string_view.h:307
ETL_CONSTEXPR14 void swap(basic_string_view &other) ETL_NOEXCEPT
Swaps with another basic_string_view.
Definition string_view.h:343
ETL_CONSTEXPR const_pointer data() const
Returns a const pointer to the first element of the internal storage.
Definition string_view.h:189
ETL_CONSTEXPR size_t length() const
Returns the size of the array.
Definition string_view.h:281
ETL_CONSTEXPR const_reverse_iterator rbegin() const
Returns a const reverse iterator to the reverse beginning of the array.
Definition string_view.h:229
bool contains(const etl::basic_string_view< T, TTraits > &view) const
Checks that the view is within this string.
Definition string_view.h:785
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:826
bool contains(const_pointer s) const
Checks that text is within this string.
Definition string_view.h:793
ETL_CONSTEXPR const_reference back() const
Returns a const reference to the last element.
Definition string_view.h:181
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:729
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:591
const_reference at(size_t i) const
Returns a const reference to the indexed value.
Definition string_view.h:333
ETL_CONSTEXPR bool empty() const
Returns true if the array size is zero.
Definition string_view.h:265
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:512
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:549
ETL_CONSTEXPR const_iterator cbegin() const
Returns a const iterator to the beginning of the array.
Definition string_view.h:205
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:834
ETL_CONSTEXPR14 basic_string_view substr(size_type position=0, size_type count=npos) const
Returns a substring.
Definition string_view.h:371
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:809
ETL_CONSTEXPR const_reference front() const
Returns a const reference to the first element.
Definition string_view.h:173
ETL_CONSTEXPR const_reference operator[](size_t i) const
Returns a const reference to the indexed value.
Definition string_view.h:325
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:680
ETL_CONSTEXPR const_iterator end() const
Returns a const iterator to the end of the array.
Definition string_view.h:213
ETL_CONSTEXPR basic_string_view(const T *begin_, size_t size_)
Construct from pointer/size.
Definition string_view.h:155
ETL_CONSTEXPR size_t size() const
Returns the size of the array.
Definition string_view.h:273
The base class for basic_string_view exceptions.
Definition string_view.h:58
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
Definition integral_limits.h:516
Definition string_view.h:72
Definition string_view.h:86
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:871
Character traits for any character type.
Definition char_traits.h:120
pair holds two objects of arbitrary type
Definition utility.h:164