BasicStringView#
Fully qualified name: omni::structuredlog::BasicStringView
Defined in omni/structuredlog/StringView.h
-
template<class CharT, class Traits = std::char_traits<CharT>>
class BasicStringView : public carb::cpp::basic_string_view<CharT, std::char_traits<CharT>># An extension of carb::cpp::basic_string_view that can handle nullptr and
std::basic_string
as inputs.- Template Parameters:
CharT – The char type pointed to by the view.
Traits – The type traits for
CharT
.
Public Types
-
using const_iterator = omni::detail::PointerIterator<const_pointer, basic_string_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
-
inline constexpr BasicStringView()#
-
inline constexpr BasicStringView(const CharT *s)#
Create a string view from a C string.
- Parameters:
s – [in] The C string to create a view into. This original pointer continues to be used and nothing is copied.
-
inline constexpr BasicStringView(const CharT *s, size_t len)#
Create a string view from a char buffer.
- Parameters:
s – [in] The char buffer to create a view into. This does not need to be null terminated. This original pointer continues to be used and nothing is copied.
len – [in] The length of the view into
s
, in characters.
-
inline constexpr BasicStringView(const std::basic_string<CharT> &s)#
Create a string view from a std::basic_string.
- Parameters:
s – [in] The string to create this string view for.
-
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 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.Note
Unlike
std::basic_string::data()
and string literals, this function returns a pointer to a buffer that is not necessarily null-terminated, for example a substring view (e.g. from remove_suffix()). Therefore, it is typically a mistake to passdata()
to a routine that takes just aconst CharT*
and expects a null- terminated string.- Returns:
A const_pointer to the underlying character array.
-
inline constexpr size_type size() const noexcept#
Returns the number of characters.
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.
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_string_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 remove_suffix(size_type n) noexcept#
Shrinks the view by moving its end backward.
Moves the end of the view back by
n
characters. The behavior is undefined ifn > size()
.- Parameters:
n – Number of characters to remove from the end of the view.
-
inline constexpr void swap(basic_string_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_string_view substr(
- size_t pos,
- size_t count = npos,
Returns a substring.
Returns a view of the substring
[pos, pos + rcount)
, wherercount
is the smaller ofcount
andsize() - pos.
-
inline constexpr int compare(basic_string_view v) const noexcept#
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.
- inline constexpr int compare( ) const#
Compares two views.
Equivalent to
substr(pos1, count1).compare(v)
.See also
compare(basic_string_view) 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) const noexcept
- inline constexpr int compare( ) const#
Compares two views.
Equivalent to
substr(pos1, count1).compare(v.substr(pos2, count2))
.See also
compare(basic_string_view) 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) const noexcept
-
inline constexpr int compare(const CharT *s) const#
Compares two views.
Equivalent to
compare(basic_string_view(s))
.See also
compare(basic_string_view) const noexcept
- Parameters:
s – Pointer to the null-terminated character string to compare to.
- Returns:
see compare(basic_string_view) const noexcept
- inline constexpr int compare( ) const#
Compares two views.
Equivalent to
substr(pos1, count1).compare(basic_string_view(s))
.See also
compare(basic_string_view) 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 null-terminated character string to compare to.
- Returns:
see compare(basic_string_view) const noexcept
- inline constexpr int compare( ) const#
Compares two views.
Equivalent to
substr(pos1, count1).compare(basic_string_view(s, count2))
. Behavior is undefined if[s, s+count2)
is not a valid contiguous range.See also
compare(basic_string_view) 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) const noexcept
- inline constexpr bool starts_with(
- basic_string_view 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.
-
inline constexpr bool starts_with(const CharT *s) const#
Checks if the string view starts with the given prefix.
Effectively returns
starts_with(basic_string_view(s))
.- Parameters:
s – A null-terminated character string.
- Returns:
true
if the string view begins with the provided prefix,false
otherwise.
-
inline constexpr bool ends_with(basic_string_view sv) const noexcept#
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.
-
inline constexpr bool ends_with(const CharT *s) const#
Checks if the string view ends with the given suffix.
Effectively returns
ends_with(basic_string_view(s))
.- Parameters:
s – A null-terminated character string.
- Returns:
true
if the string view ends with the provided suffix,false
otherwise.
-
inline constexpr bool contains(basic_string_view sv) const noexcept#
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.
-
inline constexpr bool contains(const CharT *s) const#
Checks if the string view contains the given substring or character.
Effectively
find(s) != npos
.- Parameters:
s – A null-terminated character string.
- Returns:
true
if the string view contains the provided substring,false
otherwise.
- inline constexpr size_type find(
- basic_string_view v,
- size_type pos = 0,
Find characters in the view.
Finds the first substring equal to 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 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#
Find characters in the view.
Finds the first substring equal to the given character sequence. Equivalent to
find(basic_string_view(s, count), pos)
. Complexity isO(size() * count)
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.
- inline constexpr size_type find( ) const#
Find characters in the view.
Finds the first substring equal to the given character sequence. Equivalent to
find(basic_string_view(s), pos)
. Complexity isO(size() * Traits::length(s))
at worst.- Parameters:
s – Pointer to a character string 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. 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 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#
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() * count)
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.
- inline constexpr size_type rfind( ) const#
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), pos)
. Complexity isO(size() * Traits::length(s))
at worst.- Parameters:
s – Pointer to a null-terminated character string 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_first_of(
- basic_string_view 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#
Find first occurrence of characters.
Equivalent to
find_first_of(basic_string_view(s, count), pos)
. Complexity isO(size() * count)
at worst.See also
- 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( ) const#
Find first occurrence of characters.
Equivalent to
find_first_of(basic_string_view(s, Traits::length(s)), pos)
. Complexity isO(size() * count)
at worst.See also
- 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( ) 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. 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
- 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#
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
- 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( ) const#
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), pos)
. Complexity isO(size() * Traits::length(s))
at worst.See also
- 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 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,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#
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,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( ) const#
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), pos)
. Complexity isO(size() * Traits::length(s))
at worst.See also
find_first_not_of(basic_string_view,size_type) const noexcept
- 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 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,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#
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,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( ) const#
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), pos)
, Complexity isO(size() * Traits::length(s))
at worst.See also
find_last_not_of(basic_string_view,size_type) const noexcept
- Parameters:
s – Pointer to a null-terminated string of characters to compare.
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.