basic_zstring_view#
Fully qualified name: carb::cpp::basic_zstring_view
Defined in carb/cpp/ZStringView.h
-
template<class CharT, class Traits = std::char_traits<CharT>>
class basic_zstring_view# The class template basic_zstring_view describes an object that can refer to a constant contiguous sequence of elements with the first element of the sequence at position zero, and where a null-terminator can be found after the last element.
This implementation of
zstring_view
is a guaranteed ABI- and interop-safetype.
While similar to
basic_string_view andstd::basic_string_view
, there are a few changes to enforce that views are always null-terminated:Constructors will
throw
or CARB_CHECK if the view is not null-terminated.The iterator constructor and Ranges constructor are deleted.
The basic_zstring_view::c_str() function is provided to explicitly indicate support for C-style strings.
basic_string_view::remove_suffix() is not present in
basic_zstring_view
.substr(size_t)const is distinct from substr(size_t,size_t)const; the former can return a
basic_zstring_view
but the latter must return a basic_string_view.Added conversion operators to
std::basic_string_view
and basic_string_view.
Warning
This implementation treats cases where null-terminated strings would be iterated without bound as a security risk and some functions from
std::basic_string_view
are either not present in this implementation or require passing unsafe_length. The following functions are deleted or changed in this implementation:basic_zstring_view(const CharT*)
is deleted, howeverbasic_zstring_view(const CharT (&)[N])
exists to allow both literal and bounded arrays to be use in a similar fashion. There also existsbasic_zstring_view(unsafe_length_t, const CharT*)
to opt in to unsafe behavior.find_first_of(const CharT*, size_type = 0)
is deleted, howeverfind_first_of(basic_zstring_view, size_type = 0)
will be implicitly invoked for literal strings and bounded arrays. There also existsfind_first_of(unsafe_length_t, const CharT*, size_type = 0)
to opt in to unsafe behavior.find_last_of(const CharT*, size_type = 0)
is deleted, howeverfind_last_of(basic_zstring_view, size_type = 0)
will be implicitly invoked for literal strings and bounded arrays. There also existsfind_last_of(unsafe_length_t, const CharT*, size_type = 0)
to opt in to unsafe behavior.find_first_not_of(const CharT*, size_type = 0)
is deleted, howeverfind_first_not_of(basic_zstring_view, size_type = 0)
will be implicitly invoked for literal strings and bounded arrays. There also existsfind_first_not_of(unsafe_length_t, const CharT*, size_type = 0)
to opt in to unsafe behavior.find_last_not_of(const CharT*, size_type = 0)
is deleted, howeverfind_last_not_of(basic_zstring_view, size_type = 0)
will be implicitly invoked for literal strings and bounded arrays. There also existsfind_last_not_of(unsafe_length_t, const CharT*, size_type = 0)
to opt in to unsafe behavior.
Note
For purposes of this class, “null terminator” refers to a default-initialized
CharT
(e.g.CharT{}
).- Template Parameters:
CharT – character type
Traits – A traits class specifying the operations on the character type. Like for
std::basic_string
,Traits::char_type
must name the same type asCharT
or the program is ill-formed.
Public Types
-
using const_iterator = omni::detail::PointerIterator<const_pointer, basic_zstring_view>#
implementation defined constant LegacyRandomAccessIterator and LegacyContiguousIterator whose value_type is CharT.
-
using iterator = const_iterator#
const_iterator
Note
iterator
andconst_iterator
are the same type because string views are views into constant character sequences.
-
using const_reverse_iterator = std::reverse_iterator<const_iterator>#
std::reverse_iterator<const_iterator>
-
using reverse_iterator = const_reverse_iterator#
const_reverse_iterator
Public Functions
-
constexpr basic_zstring_view() noexcept = default#
Constructs a basic_zstring_view.
Constructs an empty basic_zstring_view. After construction, data() is equal to a pointer to a null terminator and size() is equal to
0
.
- constexpr basic_zstring_view(
- const basic_zstring_view &other,
Constructs a basic_zstring_view.
Constructs a view of the same content as
other
. After construction, data() is equal toother.data()
and size() is equal toother.size()
.- Parameters:
other – The string view to copy.
-
inline constexpr basic_zstring_view(const CharT *s, size_type count)#
Constructs a basic_zstring_view.
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. If exceptions are disabled ands[count]
is not a null terminator, a CARB_CHECK will occur. After construction, data() is equal tos
, and size() is equal tocount
.- Throws:
std::out_of_range – if
s[count]
is not a null terminator and exceptions are enabled.- Parameters:
s – The character array to view.
count – The number of characters in
s
to view.s[count]
must be a null terminator.
-
template<size_t N>
inline constexpr basic_zstring_view(
)# Constructs a basic_zstring_view.
Constructs a view of a string contained in a fixed-size character array
s
, not including the terminating null character. The length of the view is determined by the count of characters preceding the first null-terminator. After construction, data() is equal tos
, and size() is equal to the count of characters preceding the first null-terminator.Note
This constructor is a Carbonite extension and provided for additional security.
Warning
If no null terminator is present in in
[s, s + N)
, this function will throwstd::out_of_range
if exceptions are enabled. If exceptions are not enabled, a CARB_CHECK will occur.- Throws:
std::out_of_range – if exceptions are enabled and a null terminator is not found in
[s, s + N)
.- Parameters:
s – A fixed-size array containing a string. A null terminator must be present in
[s, s + N)
.
- inline constexpr basic_zstring_view(
- unsafe_length_t,
- const CharT *s,
Constructs a basic_zstring_view.
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 byTraits::length(s)
. Ifs
isnullptr
, the result is an empty string (with data() pointing to a null terminator, as with the default constructor and size()0
); otherwise, the behavior is undefined if[s, s + Traits::length(s)]
is not a valid range. Ifs
is notnullptr
, after construction data() is equal tos
, and size() is equal toTraits::length(s)
.Note
basic_zstring_view(const CharT*)
does not exist for security purposes; this constructor exists in its place to specifically opt-in to unsafe string lengths.- Parameters:
s – The null-terminated character string to view.
-
template<class It>
constexpr basic_zstring_view(It, It) = delete# Iterator constructor is deleted for zstring_view.
The rationale behind this is two-fold:
The iteration range would need to include a null terminator that is not at or beyond
end
.The constructor would need to be O(n) to find the null terminator.
Both of these points are a significant departure from string_view and violate our ‘no surprises’ rule. Instead it is preferred to use a different constructor such as basic_zstring_view(const CharT*,size_type).
-
template<class R>
explicit constexpr basic_zstring_view(R&&) = delete# Ranges constructor is deleted for zstring_view.
The rationale behind this is two-fold:
The range would need to include a null terminator.
The constructor would need to be O(n) to find the null terminator.
Both of these points are a significant departure from string_view and violate our ‘no surprises’ rule. Instead it is preferred to use a different constructor such as basic_zstring_view(const CharT*,size_type).
-
template<typename T, typename = std::enable_if_t<!std::is_pointer_v<T> && std::is_same_v<T, std::basic_string<CharT, Traits>>>>
inline constexpr basic_zstring_view( - const T &s,
Implicit conversion from
std::basic_string
to basic_zstring_view.Construct a basic_zstring_view from a
std::basic_string
. The construction is implicit to mimic the behavior of std::basic_string<CharT,Traits,Allocator>::operator basic_string_view.- Parameters:
s – An instance of
std::basic_string
.
-
constexpr basic_zstring_view(std::nullptr_t) = delete#
basic_zstring_view cannot be constructed from nullptr.
- constexpr basic_zstring_view &operator=(
- const basic_zstring_view &view,
Assigns a view.
- Parameters:
view – The view to replace
*this
with.- Returns:
*this
-
inline constexpr const_iterator begin() const noexcept#
Returns an iterator to the beginning.
- Returns:
A const_iterator to the first character of the view.
-
inline constexpr const_iterator cbegin() const noexcept#
Returns an iterator to the beginning.
- Returns:
A const_iterator to the first character of the view.
-
inline constexpr const_iterator end() const noexcept#
Returns an iterator to the end.
- Returns:
A const_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.
-
inline constexpr const_iterator cend() const noexcept#
Returns an iterator to the end.
- Returns:
A const_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.
-
inline constexpr const_reverse_iterator rbegin() const noexcept#
Returns a reverse iterator to the beginning.
- Returns:
A const_reverse_iterator to the first character of the reversed view. It corresponds to the last character of the non-reversed view.
-
inline constexpr const_reverse_iterator crbegin() const noexcept#
Returns a reverse iterator to the beginning.
- Returns:
A const_reverse_iterator to the first character of the reversed view. It corresponds to the last character of the non-reversed view.
-
inline constexpr const_reverse_iterator rend() const noexcept#
Returns a reverse iterator to the end.
- Returns:
a const_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.
-
inline constexpr const_reverse_iterator crend() const noexcept#
Returns a reverse iterator to the end.
- Returns:
a const_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.
- inline constexpr const_reference operator[](
- size_type pos,
Accesses the specified character.
Returns a const reference to the character at the specified position. No bounds checking is performed: the behavior is undefined if
pos >= size()
.- Parameters:
pos – The position of the character to return.
- Returns:
A const_reference to the requested character.
-
inline constexpr const_reference at(size_type pos) const#
Accesses the specified character with bounds checking.
Returns a const reference to the character at the specified position. Bounds checking is performed.
- Throws:
std::out_of_range – Invalid access:
pos
is at or after size().- Parameters:
pos – The position of the character to return.
- Returns:
A const_reference to the requested character
-
inline constexpr const_reference front() const noexcept#
Accesses the first character.
- Returns:
A const_reference to the first character in the view. The behavior is undefined if empty() is
true
.
-
inline constexpr const_reference back() const noexcept#
Accesses the last character.
- Returns:
A const_reference to the last character in the view. The behavior is undefined if empty() is
true
.
-
inline constexpr const_pointer data() const noexcept#
Returns a pointer to the first character of a view.
Returns a pointer to the underlying null-terminated 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.data()[size()]
is guaranteed to be a null terminator.- Returns:
A const_pointer to the underlying null-terminated character array.
-
inline constexpr const_pointer c_str() const noexcept#
Returns a pointer to the first character of a view.
Returns a pointer to the underlying null-terminated 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.data()[size()]
is guaranteed to be a null terminator.- Returns:
A const_pointer to the underlying null-terminated character array.
-
inline constexpr size_type size() const noexcept#
Returns the number of characters in the view, not including the null terminator.
Returns the number of
CharT
characters in the view, i.e.std::distance(begin(), end())
.- Returns:
The number of
CharT
elements in the view.
-
inline constexpr size_type length() const noexcept#
Returns the number of characters in the view, not including the null terminator.
Returns the number of
CharT
characters in the view, i.e.std::distance(begin(), end())
.- Returns:
The number of
CharT
elements in the view.
-
inline constexpr size_type max_size() const noexcept#
Returns the maximum number of characters.
The largest possible number of char-like objects that can be referred to by a basic_zstring_view.
- Returns:
Maximum number of characters.
-
inline constexpr bool empty() const noexcept#
Checks whether the view is empty.
Checks if the view has no characters, i.e. whether size() is
0
.- Returns:
true
if the view is empty,false
otherwise.
-
inline constexpr void remove_prefix(size_type n) noexcept#
Shrinks the view by moving its start forward.
Moves the start of the view forward by
n
characters. The behavior is undefined ifn > size()
.- Parameters:
n – Number of characters to remove from the start of the view.
-
inline constexpr void swap(basic_zstring_view &v) noexcept#
Swaps the contents.
Exchanges the view with that of
v
.- Parameters:
v – View to swap with.
- inline constexpr size_type copy( ) const#
Copies characters.
Copies the substring
[pos, pos + rcount)
to the character array pointed to bydest
, wherercount
is the smaller ofcount
andsize() - pos
. Equivalent toTraits::copy(dest, data() + pos, rcount)
.
-
inline constexpr basic_zstring_view substr(size_t pos) const#
Returns a null-terminated substring.
Returns a view of the substring
[pos, size())
.- Throws:
- Parameters:
pos – Position of the first character.
- Returns:
A basic_zstring_view (null terminated) of the substring
[pos, size())
.
- inline constexpr basic_string_view<CharT, Traits> substr(
- size_t pos,
- size_t count,
Returns a substring.
Returns a view of the substring
[pos, pos + rcount)
, wherercount
is the smaller ofcount
andsize() - pos.
- Throws:
- Parameters:
pos – Position of the first character.
count – Requested length.
- Returns:
A basic_string_view (not null-terminated) of the substring
[pos, pos + std::min(size() - pos, count))
.
- inline constexpr int compare(
- basic_string_view<CharT, Traits> v,
Compares two views.
The length rlen of the sequences to compare is the smaller of size() and
v.size()
. The function compares the two views by callingtraits::compare(data(), v.data(), rlen)
, and returns as follows:A value less than zero (
<0
) if:A value of zero (
0
) if:A value greater than zero (
>0
) if:
- Parameters:
v – View to compare
- Returns:
A negative value if
*this
is less than the other character sequence,0
if both character sequences are equal, positive value if*this
is greater than the other character sequence. See above.
-
template<class T, std::enable_if_t<!is_bounded_array_v<remove_cvref_t<T>> && std::is_convertible_v<T, const_pointer>, bool> = false>
inline constexpr int compare( - T &&s,
Compares a view with a null terminated string.
Accepts a null-terminated string. See compare(basic_string_view<CharT, Traits>) const noexcept for details.
Note
This function is not considered harmful, as the memory accessed is bounded by the size of this string.
- Parameters:
s – A null terminated string to compare. Behavior is undefined if
s
is not a pointer to a null-terminated string ofvalue_type
characters andsize() + 1
is greater than the size of the character array.- Returns:
A negative value if
*this
is less than the other character sequence,0
if both character sequences are equal, positive value if*this
is greater than the other character sequence. See above.
- inline constexpr int compare(
- size_type pos1,
- size_type count1,
- basic_string_view<CharT, Traits> v,
Compares two views.
Equivalent to
substr(pos1, count1).compare(v)
.See also
compare(basic_string_view<CharT, Traits>) const noexcept, substr()
- Throws:
- Parameters:
pos1 – Position of the first character in this view to compare.
count1 – Number of characters of this view to compare.
v – View to compare.
- Returns:
see compare(basic_string_view<CharT, Traits>) const noexcept
- inline constexpr int compare( ) const#
Compares a substring of
*this
with a null terminated string.Equivalent to
substr(pos1, count1).compare(unsafe_length, v)
.See also
compare(basic_string_view<CharT, Traits>) const noexcept, substr()
- Throws:
- Parameters:
pos1 – Position of the first character in this view to compare.
count1 – Number of characters of this view to compare.
s – A null terminated string to compare. Behavior is undefined if
s
is not a pointer to a null- terminated string ofvalue_type
characters andcount1 + 1
is greater than the size of the character array.
- Returns:
see compare(basic_string_view<CharT, Traits>) const noexcept
- inline constexpr int compare(
- size_type pos1,
- size_type count1,
- basic_string_view<CharT, Traits> v,
- size_type pos2,
- size_type count2,
Compares two views.
Equivalent to
substr(pos1, count1).compare(v.substr(pos2, count2))
.See also
compare(basic_string_view<CharT, Traits>) const noexcept, substr()
- Throws:
- Parameters:
pos1 – Position of the first character in this view to compare.
count1 – Number of characters of this view to compare.
v – View to compare.
pos2 – Position of the first character of the given view to compare.
count2 – Number of characters of the given view to compare.
- Returns:
see compare(basic_string_view<CharT, Traits>) const noexcept
- inline constexpr int compare( ) const#
Compares two views.
Equivalent to
substr(pos1, count1).compare(basic_string_view<CharT, Traits>(s, count2))
. Behavior is undefined if[s, s+count2)
is not a valid contiguous range.See also
compare(basic_string_view<CharT, Traits>) const noexcept, substr()
- Throws:
- Parameters:
pos1 – Position of the first character in this view to compare.
count1 – Number of characters of this view to compare.
s – Pointer to the character string to compare to.
count2 – Number of characters of
s
to compare.
- Returns:
see compare(basic_string_view<CharT, Traits>) const noexcept
- inline constexpr bool starts_with(
- basic_string_view<CharT, Traits> sv,
Checks if the string view starts with the given prefix.
Effectively returns
substr(0, sv.size()) == sv
.- Parameters:
sv – A string view which may be a result of implicit conversion from
std::basic_string
.- Returns:
true
if the string view begins with the provided prefix,false
otherwise.
-
inline constexpr bool starts_with(CharT ch) const noexcept#
Checks if the string view starts with the given prefix.
Effectively returns
!empty() && Traits::eq(front(), ch)
.- Parameters:
ch – A single character.
- Returns:
true
if the string view begins with the provided prefix,false
otherwise.
-
template<class T, std::enable_if_t<!is_bounded_array_v<remove_cvref_t<T>> && std::is_convertible_v<T, const_pointer>, bool> = false>
inline constexpr bool starts_with( - T &&s,
Checks if the string view starts with the given prefix.
Effectively returns
starts_with(basic_string_view(s, traits_type::length(s, size() + 1)))
.- Parameters:
s – A null terminated string to compare. Behavior is undefined if
s
is not a pointer to a null- terminated string ofvalue_type
characters andsize() + 1
is greater than the size of the character array.- Returns:
true
if the string view begins with the provided prefix,false
otherwise.
- inline constexpr bool ends_with(
- basic_string_view<CharT, Traits> sv,
Checks if the string view ends with the given suffix.
Effectively returns
size() >= sv.size() && compare(size() - sv.size(), npos, sv) == 0
.- Parameters:
sv – A string view which may be a result of implicit conversion from
std::basic_string
.- Returns:
true
if the string view ends with the provided suffix,false
otherwise.
-
inline constexpr bool ends_with(CharT ch) const noexcept#
Checks if the string view ends with the given suffix.
Effectively returns
!empty() && Traits::eq(back(), ch)
.- Parameters:
ch – A single character.
- Returns:
true
if the string view ends with the provided suffix,false
otherwise.
-
template<class T, std::enable_if_t<!is_bounded_array_v<remove_cvref_t<T>> && std::is_convertible_v<T, const_pointer>, bool> = false>
inline constexpr bool ends_with( - T &&s,
Checks if the string view ends with the given prefix. (Unsafe)
Effectively returns
ends_with(basic_string_view(s, traits_type::length(s)))
, but it will not check more that size() + 1 when looking for a terminator ins
.- Parameters:
s – A null terminated string to compare. Behavior is undefined if
s
is not a pointer to a null- terminated string ofvalue_type
characters andsize() + 1
is greater than the size of the character array.- Returns:
true
if the string view ends with the provided prefix,false
otherwise.
- inline constexpr bool contains(
- basic_string_view<CharT, Traits> sv,
Checks if the string view contains the given substring or character.
Effectively
find(sv) != npos
.- Parameters:
sv – A string view.
- Returns:
true
if the string view contains the provided substring,false
otherwise.
-
inline constexpr bool contains(CharT c) const noexcept#
Checks if the string view contains the given substring or character.
Effectively
find(c) != npos
.- Parameters:
c – A single character.
- Returns:
true
if the string view contains the provided substring,false
otherwise.
-
template<class T, std::enable_if_t<!is_bounded_array_v<remove_cvref_t<T>> && std::is_convertible_v<T, const_pointer>, bool> = false>
inline constexpr bool contains( - T &&s,
Checks if the string view contains the given substring or character.
Effectively
find(basic_string_view(s, traits_type::length(size() + 1))) != npos
.- Parameters:
s – A null terminated string to compare. Behavior is undefined if
s
is not a pointer to a null- terminated string ofvalue_type
characters andsize() + 1
is greater than the size of the character array.- Returns:
true
if the string view contains the provided substring,false
otherwise.
- inline constexpr size_type find(
- basic_string_view<CharT, Traits> v,
- size_type pos = 0,
Find characters in the view.
Finds the first substring equal to the given character sequence. Complexity is
O(size()^2)
at worst.- Parameters:
v – View to search for.
pos – Position at which to start the search.
- Returns:
Position of the first character of the found substring, or npos if no such substring is found.
- inline constexpr size_type find( ) const noexcept#
Find characters in the view.
Finds the first substring equal to the given character sequence. Equivalent to
find(basic_string_view(std::addressof(ch), 1))
. Complexity isO(size())
at worst.- Parameters:
ch – Character to search for.
pos – Position at which to start the search.
- Returns:
Position of the first character of the found substring, or npos if no such substring is found.
- inline constexpr size_type find( ) const noexcept#
Find characters in the view.
Finds the first substring equal to the given character sequence. Equivalent to
find(basic_string_view<CharT, Traits>(s, count), pos)
. Complexity isO(size()^2)
at worst.- Parameters:
s – Pointer to a character string to search for.
pos – Position at which to start the search.
count – Length of substring to search for.
- Returns:
Position of the first character of the found substring, or npos if no such substring is found.
-
template<class T, std::enable_if_t<!is_bounded_array_v<remove_cvref_t<T>> && std::is_convertible_v<T, const_pointer>, bool> = false>
inline constexpr size_type find(
) const noexcept# Find characters in the view.
Finds the first substring equal to the given character sequence. Equivalent to
find(basic_string_view(s, traits_type::length(s, size() + 1)), pos)
. Complexity isO(size()^2)
at worst.- Parameters:
s – A null terminated string to compare. Behavior is undefined if
s
is not a pointer to a null- terminated string ofvalue_type
characters andsize() + 1
is greater than the size of the character array.pos – Position at which to start the search.
- Returns:
Position of the first character of the found substring, or npos if no such substring is found.
- inline constexpr size_type rfind(
- basic_string_view<CharT, Traits> v,
- size_type pos = npos,
Find the last occurrence of a substring.
Finds the last substring equal to the given character sequence. Search begins at
pos
, i.e. the found substring must not being is a position followingpos
. If npos or any value not smaller thansize()-1
is passed as pos, the whole string will be searched. Complexity isO(size()^2)
at worst.- Parameters:
v – View to search for.
pos – Position at which to start the search.
- Returns:
Position of the first character of the found substring, or npos if no such substring is found.
- inline constexpr size_type rfind( ) const noexcept#
Find the last occurrence of a substring.
Finds the last substring equal to the given character sequence. Search begins at
pos
, i.e. the found substring must not being is a position followingpos
. If npos or any value not smaller thansize()-1
is passed as pos, the whole string will be searched. Equivalent torfind(basic_string_view(std::addressof(ch), 1), pos)
. Complexity isO(size())
at worst.- Parameters:
ch – Character to search for.
pos – Position at which to start the search.
- Returns:
Position of the first character of the found substring, or npos if no such substring is found.
- inline constexpr size_type rfind( ) const noexcept#
Find the last occurrence of a substring.
Finds the last substring equal to the given character sequence. Search begins at
pos
, i.e. the found substring must not being is a position followingpos
. If npos or any value not smaller thansize()-1
is passed as pos, the whole string will be searched. Equivalent torfind(basic_string_view(s, count), pos)
. Complexity isO(size()^2)
at worst.- Parameters:
s – Pointer to a character string to search for.
pos – Position at which to start the search.
count – Length of substring to search for.
- Returns:
Position of the first character of the found substring, or npos if no such substring is found.
-
template<class T, std::enable_if_t<!is_bounded_array_v<remove_cvref_t<T>> && std::is_convertible_v<T, const_pointer>, bool> = false>
inline constexpr size_type rfind(
) const noexcept# Find the last occurrence of a substring.
Finds the last substring equal to the given character sequence. Search begins at
pos
, i.e. the found substring must not being is a position followingpos
. If npos or any value not smaller thansize()-1
is passed as pos, the whole string will be searched. Equivalent torfind(basic_string_view(s, traits_type::length(s, size() + 1)), pos)
. Complexity isO(size()^2)
at worst.- Parameters:
s – A null terminated string to compare. Behavior is undefined if
s
is not a pointer to a null- terminated string ofvalue_type
characters andsize() + 1
is greater than the size of the character array.pos – Position at which to start the search.
- Returns:
Position of the first character of the found substring, or npos if no such substring is found.
- inline constexpr size_type find_first_of(
- basic_string_view<CharT, Traits> v,
- size_type pos = 0,
Find first occurrence of characters.
Finds the first occurrence of any of the characters of
v
in this view, starting as positionpos
. Complexity isO(size() * v.size())
at worst.- Parameters:
v – View to search for.
pos – Position at which to start the search.
- Returns:
Position of the first occurrence of any character of the substring, or npos if no such character is found.
- inline constexpr size_type find_first_of( ) const noexcept#
Find first occurrence of characters.
Equivalent to
find_first_of(basic_string_view(std::addressof(ch), 1), pos)
. Complexity isO(size())
at worst.See also
- Parameters:
ch – Character to search for.
pos – Position at which to start the search.
- Returns:
Position of the first occurrence of any character of the substring, or npos if no such character is found.
- inline constexpr size_type find_first_of( ) const noexcept#
Find first occurrence of characters.
Equivalent to
find_first_of(basic_string_view(s, count), pos)
. Complexity isO(size() * count)
at worst.See also
find_first_of(basic_string_view<CharT,Traits>,size_type) const noexcept
- Parameters:
s – Pointer to a string of characters to search for.
pos – Position at which to start the search.
count – Length of the string of characters to search for.
- Returns:
Position of the first occurrence of any character of the substring, or npos if no such character is found.
- inline constexpr size_type find_first_of(
- unsafe_length_t,
- const CharT *s,
- size_type pos = 0,
Find first occurrence of characters. (Unsafe)
Finds the first occurrence of any of the characters of
v
in this view, starting as positionpos
. Complexity isO(size() * traits_type::length(s))
at worst.- Parameters:
s – Pointer to a null-terminated string of characters to search for.
pos – Position at which to start the search.
- Returns:
Position of the first occurrence of any character of the substring, or npos if no such character is found.
- inline constexpr size_type find_last_of(
- basic_string_view<CharT, Traits> v,
- size_type pos = npos,
Find last occurrence of characters.
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. Complexity isO(size() * v.size())
at worst.- Parameters:
v – View to search for.
pos – Position at which the search is to finish.
- Returns:
Position of the last occurrence of any character of the substring, or npos if no such character is found.
- inline constexpr size_type find_last_of( ) const noexcept#
Find last occurrence of characters.
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 tofind_last_of(basic_string_view(std::addressof(ch), 1), pos)
. Complexity isO(size())
at worst.See also
find_last_of(basic_string_view<CharT,Traits>,size_type) const noexcept
- Parameters:
ch – Character to search for.
pos – Position at which the search is to finish.
- Returns:
Position of the last occurrence of any character of the substring, or npos if no such character is found.
- inline constexpr size_type find_last_of( ) const noexcept#
Find last occurrence of characters.
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 tofind_last_of(basic_string_view(s, count), pos)
. Complexity isO(size() * count)
at worst.See also
find_last_of(basic_string_view<CharT,Traits>,size_type) const noexcept
- Parameters:
s – Pointer to a string of characters to search for.
pos – Position at which the search is to finish.
count – Length of the string of characters to search for.
- Returns:
Position of the last occurrence of any character of the substring, or npos if no such character is found.
- inline constexpr size_type find_last_of(
- unsafe_length_t,
- const CharT *s,
- size_type pos = npos,
Find last occurrence of characters. (Unsafe)
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. Complexity isO(size() * traits_type::length(s))
at worst.- Parameters:
s – Pointer to a null-terminated string of characters to search for.
pos – Position at which the search is to finish.
- Returns:
Position of the last occurrence of any character of the substring, or npos if no such character is found.
- inline constexpr size_type find_first_not_of(
- basic_string_view<CharT, Traits> v,
- size_type pos = 0,
Find first absence of characters.
Finds the first character not equal to any of the characters in the given character sequence. Complexity is
O(size() * v.size())
at worst.- Parameters:
v – View to search for.
pos – Position at which to start the search.
- Returns:
Position of the first character not equal to any of the characters in the given string, or npos if no such character is found.
- inline constexpr size_type find_first_not_of( ) const noexcept#
Find first absence of characters.
Finds the first character not equal to any of the characters in the given character sequence. Equivalent to
find_first_not_of(basic_string_view(std::addressof(ch), 1), pos)
. Complexity isO(size())
at worst.See also
find_first_not_of(basic_string_view<CharT,Traits>,size_type) const noexcept
- Parameters:
ch – Character to search for.
pos – Position at which to start the search.
- Returns:
Position of the first character not equal to any of the characters in the given string, or npos if no such character is found.
- inline constexpr size_type find_first_not_of( ) const noexcept#
Find first absence of characters.
Finds the first character not equal to any of the characters in the given character sequence. Equivalent to
find_first_not_of(basic_string_view(s, count), pos)
. Complexity isO(size() * count)
at worst.See also
find_first_not_of(basic_string_view<CharT, Traits>,size_type) const noexcept
- Parameters:
s – Pointer to a string of characters to search for.
pos – Position at which to start the search.
count – Length of the string of characters to compare.
- Returns:
Position of the first character not equal to any of the characters in the given string, or npos if no such character is found.
- inline constexpr size_type find_first_not_of(
- unsafe_length_t,
- const CharT *s,
- size_type pos = 0,
Find first absence of characters. (Unsafe)
Finds the first character not equal to any of the characters in the given character sequence. Complexity is
O(size() * traits_type::length(s))
at worst.- Parameters:
s – Pointer to a null-terminated string of characters to search for.
pos – Position at which to start the search.
- Returns:
Position of the first character not equal to any of the characters in the given string, or npos if no such character is found.
- inline constexpr size_type find_last_not_of(
- basic_string_view<CharT, Traits> v,
- size_type pos = 0,
Find last absence of characters.
Finds the last character not equal to any of the characters in the given character sequence. The search considers only the interval
[0, pos]
. Complexity isO(size() * v.size())
at worst.- Parameters:
v – View to search for.
pos – Position at which to start the search.
- Returns:
Position of the last character not equal to any of the characters in the given string, or npos if no such character is found.
- inline constexpr size_type find_last_not_of( ) const noexcept#
Find last absence of characters.
Finds the last character not equal to any of the characters in the given character sequence. The search considers only the interval
[0, pos]
. Equivalent tofind_last_not_of(basic_string_view(std::addressof(ch), 1), pos)
, Complexity isO(size())
at worst.See also
find_last_not_of(basic_string_view<CharT,Traits>,size_type) const noexcept
- Parameters:
ch – Character to search for.
pos – Position at which to start the search.
- Returns:
Position of the last character not equal to any of the characters in the given string, or npos if no such character is found.
- inline constexpr size_type find_last_not_of( ) const noexcept#
Find last absence of characters.
Finds the last character not equal to any of the characters in the given character sequence. The search considers only the interval
[0, pos]
. Equivalent tofind_last_not_of(basic_string_view(s, count), pos)
, Complexity isO(size() * count)
at worst.See also
find_last_not_of(basic_string_view<CharT,Traits>,size_type) const noexcept
- Parameters:
s – Pointer to a string of characters to compare.
pos – Position at which to start the search.
count – Length of the string of characters to compare.
- Returns:
Position of the last character not equal to any of the characters in the given string, or npos if no such character is found.
- inline constexpr size_type find_last_not_of(
- unsafe_length_t,
- const CharT *s,
- size_type pos = 0,
Find last absence of characters. (Unsafe)
Finds the last character not equal to any of the characters in the given character sequence. The search considers only the interval
[0, pos]
. Complexity isO(size() * traits_type::length(s))
at worst.- Parameters:
s – Pointer to a null-terminated string of characters to search for.
pos – Position at which to start the search.
- Returns:
Position of the last character not equal to any of the characters in the given string, or npos if no such character is found.
- inline operator std::basic_string_view<CharT, Traits>(
Conversion operator to std::basic_string_view. This will make
basic_zstring_view
a StringViewLike object, which enables conversion tostd::basic_string<CharT, Traits>
(among other things).- Returns:
A copy of the string view as a
std::basic_string_view<CharT, Traits>
.
-
inline operator basic_string_view<CharT, Traits>() const noexcept#
Conversion operator to basic_string_view. This will make
basic_zstring_view
a StringViewLike object, which enables conversion to omni::string (among other things).- Returns:
A copy of the string view as a basic_string_view.