tetl 0.1.0
Embedded Template Library
|
The class template basic_string_view describes an object that can refer to a constant contiguous sequence of char-like objects with the first element of the sequence at position zero. A typical implementation holds only two members: a pointer to constant Char and a size. More...
#include <etl/string_view.hpp>
Public Types | |
using | const_iterator = Char const* |
using | const_pointer = Char const* |
using | const_reference = Char const& |
using | const_reverse_iterator = etl::reverse_iterator<const_iterator> |
using | difference_type = etl::ptrdiff_t |
using | iterator = const_iterator |
using | pointer = Char* |
using | reference = Char& |
using | reverse_iterator = const_reverse_iterator |
using | size_type = etl::size_t |
using | traits_type = Traits |
using | value_type = Char |
Public Member Functions | |
constexpr | basic_string_view () noexcept=default |
Default constructor. Constructs an empty basic_string_view. After construction, data() is equal to nullptr, and size() is equal to 0. | |
constexpr | basic_string_view (basic_string_view const &other) noexcept=default |
Copy constructor. Constructs a view of the same content as other. After construction, data() is equal to other.data(), and size() is equal to other.size(). | |
constexpr | basic_string_view (Char const *str) |
Constructs a view of the null-terminated character string pointed to by s, not including the terminating null character. The length of the view is determined as if by Traits::length(s). The behavior is undefined if [s, s+Traits::length(s)) is not a valid range. After construction, data() is equal to s, and size() is equal to Traits::length(s). | |
constexpr | basic_string_view (Char const *str, size_type size) |
Constructs a view of the first count characters of the character array starting with the element pointed by s. s can contain null characters. The behavior is undefined if [s, s+count) is not a valid range (even though the constructor may not access any of the elements of this range). After construction, data() is equal to s, and size() is equal to count. | |
template<typename Iter> requires (detail::RandomAccessIterator<Iter>) | |
constexpr | basic_string_view (Iter first, Iter last) |
Constructs a basic_string_view over the range [first, last). The behavior is undefined if [first, last) is not a valid range. | |
constexpr | basic_string_view (nullptr_t)=delete |
~basic_string_view () noexcept=default | |
constexpr auto | back () const -> const_reference |
Returns reference to the last character in the view. | |
constexpr auto | begin () const noexcept -> const_iterator |
Returns an iterator to the first character of the view. | |
constexpr auto | cbegin () const noexcept -> const_iterator |
Returns an iterator to the first character of the view. | |
constexpr auto | cend () const noexcept -> const_iterator |
Returns an iterator to the character following the last character of the view. This character acts as a placeholder, attempting to access it results in undefined behavior. | |
constexpr auto | compare (basic_string_view v) const noexcept -> int |
Compares two character sequences. | |
constexpr auto | compare (Char const *s) const -> int |
Compares two character sequences. Equivalent to compare(basic_string_view(s)). | |
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). | |
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, count2)) | |
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)). | |
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, count2)). | |
constexpr auto | contains (basic_string_view sv) const noexcept -> bool |
Checks if the string contains the given substring. | |
constexpr auto | contains (Char c) const noexcept -> bool |
Checks if the string contains the given substring. | |
constexpr auto | contains (Char const *s) const -> bool |
Checks if the string contains the given substring. | |
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, where rcount is the smaller of count and size() - pos. Equivalent to Traits::copy(dest, data() + pos, rcount). | |
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 character of the non-reversed view. | |
constexpr auto | crend () const noexcept -> const_reverse_iterator |
Returns a reverse iterator to the character following the last character of the reversed view. | |
constexpr auto | data () const noexcept -> const_pointer |
Returns a pointer to the underlying character array. The pointer is such that the range [data(); data() + size()) is valid and the values in it correspond to the values of the view. | |
constexpr auto | empty () const noexcept -> bool |
Checks if the view has no characters, i.e. whether size() == 0. | |
constexpr auto | end () const noexcept -> const_iterator |
Returns an iterator to the character following the last character of the view. This character acts as a placeholder, attempting to access it results in undefined behavior. | |
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. | |
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. | |
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 character string. | |
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 this view, starting at position pos. | |
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(etl::addressof(ch), 1), pos) | |
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(s, count), pos) | |
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(s), pos) | |
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. | |
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. | |
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. | |
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. | |
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. Finds the first occurence of any of the characters of v in this view, starting at position pos. | |
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. Equivalent to find_first_of(basic_string_view(&c, 1), pos) | |
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. Equivalent to find_first_of(basic_string_view(s, count), pos) | |
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. Equivalent to find_first_of(basic_string_view(s), pos) | |
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 pos. | |
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. Equivalent to find_last_not_of(basic_string_view(&c, 1), pos). | |
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. Equivalent to find_last_not_of(basic_string_view(s, count), pos). | |
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. Equivalent to find_last_not_of(basic_string_view(s), pos) | |
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. Exact search algorithm is not specified. The search considers only the interval [0; pos]. If the character is not present in the interval, npos will be returned. Finds the last occurence of any of the characters of v in this view, ending at position pos. | |
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. Exact search algorithm is not specified. The search considers only the interval [0; pos]. If the character is not present in the interval, npos will be returned. Equivalent to find_last_of(basic_string_view(&c, 1), pos). | |
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. Exact search algorithm is not specified. The search considers only the interval [0; pos]. If the character is not present in the interval, npos will be returned. Equivalent to find_last_of(basic_string_view(s, count), pos). | |
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. Exact search algorithm is not specified. The search considers only the interval [0; pos]. If the character is not present in the interval, npos will be returned. Equivalent to find_last_of(basic_string_view(s), pos). | |
constexpr auto | front () const -> const_reference |
Returns reference to the first character in the view. | |
constexpr auto | length () const noexcept -> size_type |
Returns the number of Char elements in the view, i.e. etl::distance(begin(), end()). | |
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. | |
constexpr auto | operator= (basic_string_view const &view) noexcept -> basic_string_view &=default |
Replaces the view with that of view. | |
constexpr auto | operator[] (size_type pos) const -> const_reference |
Returns a const reference to the character at specified location pos . | |
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 character of the non-reversed view. | |
constexpr auto | remove_prefix (size_type n) -> void |
Moves the start of the view forward by n characters. | |
constexpr auto | remove_suffix (size_type n) -> void |
Moves the end of the view back by n characters. | |
constexpr auto | rend () const noexcept -> const_reverse_iterator |
Returns a reverse iterator to the character following the last character of the reversed view. | |
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 view, starting at position pos. | |
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(&c, 1), pos). | |
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(s, count), pos). | |
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(s), pos). | |
constexpr auto | size () const noexcept -> size_type |
Returns the number of Char elements in the view, i.e. etl::distance(begin(), end()). | |
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. | |
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. | |
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 character string. | |
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() - pos. | |
constexpr auto | swap (basic_string_view &v) noexcept -> void |
Exchanges the view with that of v. | |
Static Public Attributes | |
static constexpr size_type | npos = size_type(-1) |
This is a special value equal to the maximum value representable by the type size_type. | |
The class template basic_string_view describes an object that can refer to a constant contiguous sequence of char-like objects with the first element of the sequence at position zero. A typical implementation holds only two members: a pointer to constant Char and a size.
using const_iterator = Char const* |
using const_pointer = Char const* |
using const_reference = Char const& |
using const_reverse_iterator = etl::reverse_iterator<const_iterator> |
using difference_type = etl::ptrdiff_t |
using iterator = const_iterator |
using pointer = Char* |
using reference = Char& |
using reverse_iterator = const_reverse_iterator |
using size_type = etl::size_t |
using traits_type = Traits |
using value_type = Char |
|
constexprdefaultnoexcept |
Default constructor. Constructs an empty basic_string_view. After construction, data() is equal to nullptr, and size() is equal to 0.
|
constexprdefaultnoexcept |
|
inlineconstexpr |
Constructs a view of the first count characters of the character array starting with the element pointed by s. s can contain null characters. The behavior is undefined if [s, s+count) is not a valid range (even though the constructor may not access any of the elements of this range). After construction, data() is equal to s, and size() is equal to count.
|
inlineconstexpr |
Constructs a view of the null-terminated character string pointed to by s, not including the terminating null character. The length of the view is determined as if by Traits::length(s). The behavior is undefined if [s, s+Traits::length(s)) is not a valid range. After construction, data() is equal to s, and size() is equal to Traits::length(s).
|
constexprdelete |
|
inlineconstexpr |
Constructs a basic_string_view over the range [first, last). The behavior is undefined if [first, last) is not a valid range.
|
defaultnoexcept |
|
inlinenodiscardconstexpr |
Returns reference to the last character in the view.
size() > 0
|
inlinenodiscardconstexprnoexcept |
Returns an iterator to the first character of the view.
|
inlinenodiscardconstexprnoexcept |
Returns an iterator to the first character of the view.
|
inlinenodiscardconstexprnoexcept |
Returns an iterator to the character following the last character of the view. This character acts as a placeholder, attempting to access it results in undefined behavior.
|
inlinenodiscardconstexprnoexcept |
Compares two character sequences.
https://en.cppreference.com/w/cpp/string/basic_string_view/compare
|
inlinenodiscardconstexpr |
Compares two character sequences. Equivalent to compare(basic_string_view(s)).
|
inlinenodiscardconstexpr |
Compares two character sequences. Equivalent to substr(pos1, count1).compare(v).
|
inlinenodiscardconstexpr |
Compares two character sequences. Equivalent to substr(pos1, count1).compare(v.substr(pos2, count2))
|
inlinenodiscardconstexpr |
Compares two character sequences. Equivalent to substr(pos1, count1).compare(basic_string_view(s)).
|
inlinenodiscardconstexpr |
Compares two character sequences. Equivalent to substr(pos1, count1).compare(basic_string_view(s, count2)).
|
inlinenodiscardconstexprnoexcept |
Checks if the string contains the given substring.
|
inlinenodiscardconstexprnoexcept |
Checks if the string contains the given substring.
|
inlinenodiscardconstexpr |
Checks if the string contains the given substring.
|
inlinenodiscardconstexprnoexcept |
Returns a reverse iterator to the first character of the reversed view. It corresponds to the last character of the non-reversed view.
|
inlinenodiscardconstexprnoexcept |
Returns a reverse iterator to the character following the last character of the reversed view.
It corresponds to the character preceding the first character of the non-reversed view. This character acts as a placeholder, attempting to access it results in undefined behavior.
|
inlinenodiscardconstexprnoexcept |
|
inlinenodiscardconstexprnoexcept |
Checks if the view has no characters, i.e. whether size() == 0.
|
inlinenodiscardconstexprnoexcept |
Returns an iterator to the character following the last character of the view. This character acts as a placeholder, attempting to access it results in undefined behavior.
|
inlinenodiscardconstexprnoexcept |
|
inlinenodiscardconstexprnoexcept |
Checks if the string view ends with the given suffix, where the prefix is a single character.
Effectively returns !empty() && Traits::eq(back(), c)
|
inlineconstexpr |
Checks if the string view ends with the given suffix, where the the prefix is a null-terminated character string.
Effectively returns ends_with(basic_string_view(s))
|
inlinenodiscardconstexprnoexcept |
Finds the first substring equal to the given character sequence. Finds the first occurence of v in this view, starting at position pos.
|
inlinenodiscardconstexprnoexcept |
Finds the first substring equal to the given character sequence. Equivalent to find(basic_string_view(etl::addressof(ch), 1), pos)
|
inlineconstexpr |
Finds the first substring equal to the given character sequence. Equivalent to find(basic_string_view(s, count), pos)
|
inlineconstexpr |
Finds the first substring equal to the given character sequence. Equivalent to find(basic_string_view(s), pos)
|
inlinenodiscardconstexprnoexcept |
Finds the first character not equal to any of the characters in the given character sequence.
|
inlinenodiscardconstexprnoexcept |
Finds the first character not equal to any of the characters in the given character sequence.
|
inlinenodiscardconstexpr |
Finds the first character not equal to any of the characters in the given character sequence.
|
inlinenodiscardconstexpr |
Finds the first character not equal to any of the characters in the given character sequence.
|
inlinenodiscardconstexprnoexcept |
Finds the first character equal to any of the characters in the given character sequence. Finds the first occurence of any of the characters of v in this view, starting at position pos.
|
inlinenodiscardconstexprnoexcept |
Finds the first character equal to any of the characters in the given character sequence. Equivalent to find_first_of(basic_string_view(&c, 1), pos)
|
inlineconstexpr |
Finds the first character equal to any of the characters in the given character sequence. Equivalent to find_first_of(basic_string_view(s, count), pos)
|
inlineconstexpr |
Finds the first character equal to any of the characters in the given character sequence. Equivalent to find_first_of(basic_string_view(s), pos)
|
inlinenodiscardconstexprnoexcept |
Finds the last character not equal to any of the characters of v in this view, starting at position pos.
|
inlinenodiscardconstexprnoexcept |
Finds the last character not equal to any of the characters in the given character sequence. Equivalent to find_last_not_of(basic_string_view(&c, 1), pos).
|
inlinenodiscardconstexpr |
Finds the last character not equal to any of the characters in the given character sequence. Equivalent to find_last_not_of(basic_string_view(s, count), pos).
|
inlinenodiscardconstexpr |
Finds the last character not equal to any of the characters in the given character sequence. Equivalent to find_last_not_of(basic_string_view(s), pos)
|
inlinenodiscardconstexprnoexcept |
Finds the last character equal to one of characters in the given character sequence. Exact search algorithm is not specified. The search considers only the interval [0; pos]. If the character is not present in the interval, npos will be returned. Finds the last occurence of any of the characters of v in this view, ending at position pos.
|
inlinenodiscardconstexprnoexcept |
Finds the last character equal to one of characters in the given character sequence. Exact search algorithm is not specified. The search considers only the interval [0; pos]. If the character is not present in the interval, npos will be returned. Equivalent to find_last_of(basic_string_view(&c, 1), pos).
|
inlineconstexpr |
Finds the last character equal to one of characters in the given character sequence. Exact search algorithm is not specified. The search considers only the interval [0; pos]. If the character is not present in the interval, npos will be returned. Equivalent to find_last_of(basic_string_view(s, count), pos).
|
inlineconstexpr |
Finds the last character equal to one of characters in the given character sequence. Exact search algorithm is not specified. The search considers only the interval [0; pos]. If the character is not present in the interval, npos will be returned. Equivalent to find_last_of(basic_string_view(s), pos).
|
inlinenodiscardconstexpr |
Returns reference to the first character in the view.
size() > 0
|
inlinenodiscardconstexprnoexcept |
Returns the number of Char elements in the view, i.e. etl::distance(begin(), end()).
|
inlinenodiscardconstexprnoexcept |
The largest possible number of char-like objects that can be referred to by a basic_string_view.
|
constexprdefaultnoexcept |
Replaces the view with that of view.
|
inlinenodiscardconstexpr |
Returns a const reference to the character at specified location pos
.
pos < size()
|
inlinenodiscardconstexprnoexcept |
Returns a reverse iterator to the first character of the reversed view. It corresponds to the last character of the non-reversed view.
|
inlineconstexpr |
Moves the start of the view forward by n characters.
n <= size()
|
inlineconstexpr |
Moves the end of the view back by n characters.
n <= size()
|
inlinenodiscardconstexprnoexcept |
Returns a reverse iterator to the character following the last character of the reversed view.
It corresponds to the character preceding the first character of the non-reversed view. This character acts as a placeholder, attempting to access it results in undefined behavior.
|
inlinenodiscardconstexprnoexcept |
Finds the last substring equal to the given character sequence. Finds the last occurence of v in this view, starting at position pos.
|
inlinenodiscardconstexprnoexcept |
Finds the last substring equal to the given character sequence. Equivalent to rfind(basic_string_view(&c, 1), pos).
|
inlineconstexprnoexcept |
Finds the last substring equal to the given character sequence. Equivalent to rfind(basic_string_view(s, count), pos).
|
inlineconstexprnoexcept |
Finds the last substring equal to the given character sequence. Equivalent to rfind(basic_string_view(s), pos).
|
inlinenodiscardconstexprnoexcept |
Returns the number of Char elements in the view, i.e. etl::distance(begin(), end()).
|
inlinenodiscardconstexprnoexcept |
Checks if the string view begins with the given prefix, where the prefix is a string view.
Effectively returns substr(0, sv.size()) == sv
|
inlinenodiscardconstexprnoexcept |
Checks if the string view begins with the given prefix, where the prefix is a single character.
Effectively returns !empty() && Traits::eq(front(), c)
|
inlinenodiscardconstexpr |
Checks if the string view begins with the given prefix, where the the prefix is a null-terminated character string.
Effectively returns starts_with(basic_string_view(s))
|
inlinenodiscardconstexpr |
Returns a view of the substring [pos, pos + rcount), where rcount is the smaller of count and size() - pos.
|
inlineconstexprnoexcept |
Exchanges the view with that of v.
|
staticconstexpr |
This is a special value equal to the maximum value representable by the type size_type.
The exact meaning depends on context, but it is generally used either as end of view indicator by the functions that expect a view index or as the error indicator by the functions that return a view index.