Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arene::base::string_view Class Reference

Backport of the C++17 std::string_view class. More...

Inheritance diagram for arene::base::string_view:
Inheritance graph

Public Types

using const_iterator = const_char_span::const_iterator
 Const qualified version of iterator.
 
using const_pointer = const_char_span::const_pointer
 Const qualified version of pointer.
 
using const_reference = const_char_span::const_reference
 Const qualified version of reference.
 
using const_reverse_iterator = const_char_span::const_reverse_iterator
 Alias to the const-qualified reverse iterator.
 
using difference_type = std::ptrdiff_t
 Alias associated to the type used for indexing.
 
using element_type = const_char_span::element_type
 Alias to the type associated to a single contained character.
 
using iterator = const_char_span::iterator
 Alias to the iterator associated with the string_view class.
 
using pointer = const_char_span::pointer
 Alias to the pointer type associated to the underlying data.
 
using reference = const_char_span::reference
 Alias to the reference type associated to the underlying data.
 
using reverse_iterator = const_char_span::reverse_iterator
 Alias to the reverse iterator.
 
using size_type = std::size_t
 Alias for the type associated to the size of the string.
 
using value_type = const_char_span::value_type
 Same that element_type but without any cv-qualifier.
 

Public Member Functions

constexpr string_view () noexcept=default
 Default constructor, creates an empty string_view.
 
template<std::size_t N>
constexpr string_view (character const (&literal)[N]) noexcept
 Constructor from compile time string literal or c-array.
 
constexpr string_view (raw_c_string const null_terminated_string) noexcept
 Construct a string_view from a null terminated string, non-inclusive of the null terminator.
 
constexpr string_view (raw_c_string const str, std::size_t const str_length) noexcept
 Constructor for string_view from const char* string and explicit size.
 
template<typename String, constraints< std::enable_if_t< std::is_same< String, std::string >::value > > = nullptr>
 string_view (String const &str) noexcept
 Construct a string_view from a std::string.
 
constexpr string_view (string_view &&other) noexcept=default
 Default move constructor.
 
constexpr string_view (string_view const &other) noexcept=default
 Default copy constructor.
 
 ~string_view ()=default
 Default destructor.
 
constexpr auto back () const noexcept -> const_reference
 Get the last character in the string.
 
constexpr auto begin () const noexcept -> const_iterator
 Begin const iterator.
 
constexpr auto cbegin () const noexcept -> const_iterator
 Begin const iterator.
 
constexpr auto cend () const noexcept -> const_iterator
 End const iterator.
 
constexpr auto compare (raw_c_string const other) const noexcept -> integral_comparison_result
 Compare a string_view against a null-terminated string.
 
constexpr auto compare (size_type const pos1, size_type const length1, raw_c_string const other) const noexcept -> integral_comparison_result
 Compare a substring against a null terminated string.
 
constexpr auto compare (size_type const pos1, size_type const length1, raw_c_string const other, size_type const length2) const noexcept -> integral_comparison_result
 Compare a substring against a string specified as a pointer and length.
 
constexpr auto compare (size_type const pos1, size_type const length1, string_view const other) const noexcept -> integral_comparison_result
 Compare a substring against another string view.
 
constexpr auto compare (size_type const pos1, size_type const length1, string_view const other, size_type const pos2, size_type const length2) const noexcept -> integral_comparison_result
 Compare a substring against a substring of another string view.
 
constexpr auto compare (string_view const other) const noexcept -> integral_comparison_result
 lexicographically compares two string_view, behavior similar to std::string
 
constexpr auto copy (character *const dest, size_type const n) const noexcept -> size_type
 Copy the first min(n,size()) characters to the destination buffer.
 
constexpr auto copy (character *const dest, size_type const n, size_type const pos) const noexcept -> size_type
 Copy the first min(n,size()-pos) characters to the destination buffer.
 
constexpr auto crbegin () const noexcept -> const_reverse_iterator
 Obtain a reverse iterator referring to the end of the string_view.
 
constexpr auto crend () const noexcept -> const_reverse_iterator
 Obtain a reverse iterator referring to one-before the front of the string_view.
 
constexpr auto data () const noexcept -> const_pointer
 Get a pointer to the first character in the string.
 
constexpr auto empty () const noexcept -> bool
 Query if this is the empty string.
 
constexpr auto end () const noexcept -> const_iterator
 End const iterator.
 
constexpr auto ends_with (character const chr) const noexcept -> bool
 Check if the string ends with a specific character.
 
constexpr auto ends_with (raw_c_string const other) const noexcept -> bool
 Check if the string ends with another string.
 
constexpr auto ends_with (string_view const other) const noexcept -> bool
 Check if the string ends with another string.
 
constexpr auto find (character const chr, size_type const pos=0U) const noexcept -> size_type
 Find the earliest position of the specified character within the string, starting at the specified position.
 
constexpr auto find (raw_c_string const str, size_type const pos, size_type const n) const noexcept -> size_type
 Find the earliest position of the n character string starting at str within the string, starting at the specified position.
 
constexpr auto find (raw_c_string const str, size_type const pos=0U) const noexcept -> size_type
 Find the earliest position of the given substring within the string, starting at the specified position.
 
constexpr auto find (string_view const str, size_type const pos=0U) const noexcept -> size_type
 Find the earliest position of the given substring within the string, starting at the specified position.
 
constexpr auto find_first_not_of (character const chr, size_type const pos=0U) const noexcept -> size_type
 Finds the first character not equal to the provided character.
 
constexpr auto find_first_not_of (raw_c_string const str, size_type const pos, size_type const n) 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 (raw_c_string const str, size_type const pos=0U) 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 (string_view const str, size_type const pos=0U) const noexcept -> size_type
 Finds the first character not equal to any of the characters in the given character sequence.
 
constexpr auto find_first_of (character const chr, size_type const pos=0U) const noexcept -> size_type
 Finds the first character equal to the specified character.
 
constexpr auto find_first_of (raw_c_string const str, size_type const pos, size_type const n) const noexcept -> size_type
 Finds the first character equal to any of the characters in the given character sequence.
 
constexpr auto find_first_of (raw_c_string const str, size_type const pos=0U) const noexcept -> size_type
 Finds the first character equal to any of the characters in the given character sequence.
 
constexpr auto find_first_of (string_view const str, size_type const pos=0U) const noexcept -> size_type
 Finds the first character equal to any of the characters in the given character sequence.
 
constexpr auto find_last_not_of (character const chr, size_type const pos=npos) const noexcept -> size_type
 Finds the last character equal to the provided character.
 
constexpr auto find_last_not_of (raw_c_string const str, size_type const pos, size_type const n) const noexcept -> size_type
 Finds the last character not equal to any of the characters in the given character sequence.
 
constexpr auto find_last_not_of (raw_c_string const str, size_type const pos=npos) const noexcept -> size_type
 Finds the last character not equal to any of the characters in the given character sequence.
 
constexpr auto find_last_not_of (string_view const str, size_type const pos=npos) const noexcept -> size_type
 Finds the last character not equal to any of the characters in the given character sequence.
 
constexpr auto find_last_of (character const chr, size_type const pos=npos) const noexcept -> size_type
 Finds the last character equal to the provided character.
 
constexpr auto find_last_of (raw_c_string const str, size_type const pos, size_type const n) const noexcept -> size_type
 Finds the last character equal to one of characters in the given character sequence.
 
constexpr auto find_last_of (raw_c_string const str, size_type const pos=npos) const noexcept -> size_type
 Finds the last character equal to one of characters in the given character sequence.
 
constexpr auto find_last_of (string_view const str, size_type const pos=npos) const noexcept -> size_type
 Finds the last character equal to one of characters in the given character sequence.
 
constexpr auto front () const noexcept -> const_reference
 Get the first character in the string.
 
constexpr auto length () const noexcept -> size_type
 Get the length of the string view.
 
 operator std::string () const
 Implicit conversion to std::string. Provided since we cannot patch C++17's string_view constructor onto std::string.
 
constexpr auto operator= (string_view &&other) noexcept -> string_view &=default
 Move assignment operator for the string view.
 
constexpr auto operator= (string_view const &other) noexcept -> string_view &=default
 Assignment operator for the string view.
 
constexpr auto operator[] (std::size_t pos) const noexcept -> const_reference
 Get a character at position pos in the string.
 
constexpr auto rbegin () const noexcept -> reverse_iterator
 Obtain a reverse iterator referring to the end of the string.
 
constexpr void remove_prefix (size_type const count) noexcept
 Remove the first n characters from the string.
 
constexpr void remove_suffix (size_type const count) noexcept
 Remove the last n characters from the string.
 
constexpr auto rend () const noexcept -> reverse_iterator
 Obtain a reverse iterator referring to one-before the front of the string_view.
 
constexpr auto rfind (character const chr, size_type const pos=npos) const noexcept -> size_type
 Find the latest position of the specified character within the string, starting at the specified position.
 
constexpr auto rfind (raw_c_string const str, size_type const pos, size_type const n) const noexcept -> size_type
 Find the latest position of the n character string starting at str within the string, starting at the specified position.
 
constexpr auto rfind (raw_c_string const str, size_type const pos=npos) const noexcept -> size_type
 Find the latest position of the given substring within the string, starting at the specified position.
 
constexpr auto rfind (string_view const str, size_type const pos=npos) const noexcept -> size_type
 Find the latest position of the given substring within the string, starting at the specified position.
 
constexpr auto size () const noexcept -> size_type
 Get the length of the string view.
 
constexpr auto starts_with (character const chr) const noexcept -> bool
 Check if the string starts with a specific character.
 
constexpr auto starts_with (raw_c_string const other) const noexcept -> bool
 Check if the string starts with another string.
 
constexpr auto starts_with (string_view const other) const noexcept -> bool
 Check if the string starts with another string.
 
constexpr auto substr () const noexcept -> string_view
 Create a new string view referencing the same string as *this.
 
constexpr auto substr (size_type const pos, size_type const count=npos) const noexcept -> string_view
 Create a new string view based on a substring of the current one.
 
constexpr void swap (string_view &other) noexcept
 Swap the content of two string_view objects.
 

Static Public Member Functions

static constexpr auto fast_inequality_check (string_view const first, string_view const second) noexcept -> inequality_heuristic
 quick check that string views have the same size to quickly identify non-equal strings.
 
static constexpr auto max_size () noexcept -> size_type
 Get the maximum possible length of a string_view.
 
static constexpr auto three_way_compare (string_view const lhs, string_view const rhs) noexcept -> strong_ordering
 Compare two string_view objects lexicographically.
 

Static Public Attributes

static constexpr std::size_t npos {std::numeric_limits<std::size_t>::max()}
 Special marker value for end of string.
 

Detailed Description

Backport of the C++17 std::string_view class.

http://en.cppreference.com/w/cpp/string/basic_string_view

This implementation is minimalist but API compatible with the std:: one.

Member Typedef Documentation

◆ const_iterator

Const qualified version of iterator.

◆ const_pointer

Const qualified version of pointer.

◆ const_reference

Const qualified version of reference.

◆ const_reverse_iterator

Alias to the const-qualified reverse iterator.

◆ difference_type

Alias associated to the type used for indexing.

◆ element_type

Alias to the type associated to a single contained character.

◆ iterator

Alias to the iterator associated with the string_view class.

◆ pointer

Alias to the pointer type associated to the underlying data.

◆ reference

Alias to the reference type associated to the underlying data.

◆ reverse_iterator

◆ size_type

Alias for the type associated to the size of the string.

◆ value_type

Same that element_type but without any cv-qualifier.

Constructor & Destructor Documentation

◆ string_view() [1/7]

arene::base::string_view::string_view ( )
constexprdefaultnoexcept

Default constructor, creates an empty string_view.

Postcondition
data() == nullptr
size() == 0

◆ string_view() [2/7]

arene::base::string_view::string_view ( raw_c_string const str,
std::size_t const str_length )
inlineconstexprnoexcept

Constructor for string_view from const char* string and explicit size.

Parameters
strPointer to the first character of the string. May contain null characters.
str_lengthThe number of char elements in the string.
Postcondition
data() == str
size() == str_length
Precondition
str must point to an array of at least str_length characters, else behavior is undefined.

◆ string_view() [3/7]

template<std::size_t N>
arene::base::string_view::string_view ( character const (&) literal[N])
inlineconstexprnoexcept

Constructor from compile time string literal or c-array.

Parameters
literalstring literal used for the string_view construction
Template Parameters
NThe number of char elements in the string

◆ string_view() [4/7]

arene::base::string_view::string_view ( raw_c_string const null_terminated_string)
inlineconstexprnoexcept

Construct a string_view from a null terminated string, non-inclusive of the null terminator.

Parameters
null_terminated_stringnull terminated string
Precondition
Behavior is undefined if null_terminated_string is not a pointer to a null terminated sequence of characters.
Postcondition
data() == null_terminated_string
size() will be the count of characters from the first element in the string to the first instance of a null terminator.

◆ string_view() [5/7]

template<typename String, constraints< std::enable_if_t< std::is_same< String, std::string >::value > > = nullptr>
arene::base::string_view::string_view ( String const & str)
inlinenoexcept

Construct a string_view from a std::string.

Parameters
strThe std::string to create a view to.
Postcondition
data() == str.data()
size() == str.size()
Note
This constructor is a template rather than a non-template taking a const std::string& to avoid the possibility of unknowingly constructing a temporary std::string implicitly by passing something that is convertible to std::string such as a std::initializer_list<char>

◆ string_view() [6/7]

arene::base::string_view::string_view ( string_view const & other)
constexprdefaultnoexcept

Default copy constructor.

◆ string_view() [7/7]

arene::base::string_view::string_view ( string_view && other)
constexprdefaultnoexcept

Default move constructor.

◆ ~string_view()

arene::base::string_view::~string_view ( )
default

Default destructor.

Member Function Documentation

◆ back()

auto arene::base::string_view::back ( ) const -> const_reference
inlineconstexprnoexcept

Get the last character in the string.

Returns
A reference to the last character
Precondition
The string must not be empty
empty() != false else ARENE_PRECONDITION violation

◆ begin()

auto arene::base::string_view::begin ( ) const -> const_iterator
inlineconstexprnoexcept

Begin const iterator.

Returns
An iterator that references the first character of the string.

◆ cbegin()

auto arene::base::string_view::cbegin ( ) const -> const_iterator
inlineconstexprnoexcept

Begin const iterator.

Returns
An iterator that references the first character of the string_view.

◆ cend()

auto arene::base::string_view::cend ( ) const -> const_iterator
inlineconstexprnoexcept

End const iterator.

Returns
An iterator that is one-past the last character of the string_view.

◆ compare() [1/6]

auto arene::base::string_view::compare ( raw_c_string const other) const -> integral_comparison_result
inlineconstexprnoexcept

Compare a string_view against a null-terminated string.

Parameters
otherThe other string view to compare with
Returns
Equivalent to calling *this.compare(string_view{other}).

◆ compare() [2/6]

auto arene::base::string_view::compare ( size_type const pos1,
size_type const length1,
raw_c_string const other ) const -> integral_comparison_result
inlineconstexprnoexcept

Compare a substring against a null terminated string.

Parameters
pos1The offset of the substring to compare
length1The length of the substring to compare
otherThe other string view to compare with
Returns
Equivalent to calling *this.substr(pos1, length1).compare(string_view{other}).

◆ compare() [3/6]

auto arene::base::string_view::compare ( size_type const pos1,
size_type const length1,
raw_c_string const other,
size_type const length2 ) const -> integral_comparison_result
inlineconstexprnoexcept

Compare a substring against a string specified as a pointer and length.

Parameters
pos1The offset of the substring to compare
length1The length of the substring to compare
otherPointer to the other string to compare with
length2The length of the other string to compare
Returns
Equivalent to calling *this.substr(pos1, length1).compare(string_view{other, length2}).
Precondition
length2 is in the range of other otherwise behavior is undefined.

◆ compare() [4/6]

auto arene::base::string_view::compare ( size_type const pos1,
size_type const length1,
string_view const other ) const -> integral_comparison_result
inlineconstexprnoexcept

Compare a substring against another string view.

Parameters
pos1The offset of the substring to compare
length1The length of the substring to compare
otherThe other string view to compare with
Returns
Equivalent to calling *this.substr(pos1, length1).compare(other).

◆ compare() [5/6]

auto arene::base::string_view::compare ( size_type const pos1,
size_type const length1,
string_view const other,
size_type const pos2,
size_type const length2 ) const -> integral_comparison_result
inlineconstexprnoexcept

Compare a substring against a substring of another string view.

Parameters
pos1The offset of the substring to compare
length1The length of the substring to compare
otherThe other string view to compare with
pos2The offset of the other substring to compare
length2The length of the other substring to compare
Returns
Equivalent to calling *this.substr(pos1, length1).compare(other.substr(pos2, length2)).

◆ compare() [6/6]

auto arene::base::string_view::compare ( string_view const other) const -> integral_comparison_result
inlineconstexprnoexcept

lexicographically compares two string_view, behavior similar to std::string

Parameters
otherother string view to compare with
Returns
0 if the length of this and other are equal and all characters compare equal.
-1 if the value of the first character that does not match is lexicographically less in this than other .
-1 if the length of this is less than the length of other and all characters in the overlapping subset of this match those in other .
1 if the value of the first character that does not match is lexicographically greater in this than other .
1 if the length of this is greater than the length of other and all characters in the overlapping subset of lhs match those in other .

◆ copy() [1/2]

auto arene::base::string_view::copy ( character *const dest,
size_type const n ) const -> size_type
inlineconstexprnoexcept

Copy the first min(n,size()) characters to the destination buffer.

Parameters
destA pointer to the destination buffer.
nThe number of characters to attempt to copy.
Returns
The number of characters actually copied.

◆ copy() [2/2]

auto arene::base::string_view::copy ( character *const dest,
size_type const n,
size_type const pos ) const -> size_type
inlineconstexprnoexcept

Copy the first min(n,size()-pos) characters to the destination buffer.

Parameters
destA pointer to the destination buffer to copy the characters to.
nThe maximum number of characters to copy
posThe offset in the string of the first character to copy. If >=size() , no content is copied.
Returns
The number of characters actually copied.

◆ crbegin()

auto arene::base::string_view::crbegin ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

Obtain a reverse iterator referring to the end of the string_view.

Returns
An iterator that references the last character of the string_view.

◆ crend()

auto arene::base::string_view::crend ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

Obtain a reverse iterator referring to one-before the front of the string_view.

Returns
An iterator that references one-before the first character of the string_view

◆ data()

auto arene::base::string_view::data ( ) const -> const_pointer
inlineconstexprnoexcept

Get a pointer to the first character in the string.

Returns
A pointer to the first character in the string.

◆ empty()

auto arene::base::string_view::empty ( ) const -> bool
inlineconstexprnoexcept

Query if this is the empty string.

Returns
true IIF size() == 0.
false otherwise

◆ end()

auto arene::base::string_view::end ( ) const -> const_iterator
inlineconstexprnoexcept

End const iterator.

Returns
An iterator that is one-past the last character of the string_view.

◆ ends_with() [1/3]

auto arene::base::string_view::ends_with ( character const chr) const -> bool
inlineconstexprnoexcept

Check if the string ends with a specific character.

Parameters
chrThe character to check
Returns
true if the string is not empty and the last character is c

◆ ends_with() [2/3]

auto arene::base::string_view::ends_with ( raw_c_string const other) const -> bool
inlineconstexprnoexcept

Check if the string ends with another string.

Parameters
otherThe other string
Returns
true if the last string_length(other) characters of this are equal to those in other .
false otherwise.
Precondition
other must be a null terminated string or else behavior is undefined.

◆ ends_with() [3/3]

auto arene::base::string_view::ends_with ( string_view const other) const -> bool
inlineconstexprnoexcept

Check if the string ends with another string.

Parameters
otherThe other string
Returns
true if the last other.size() characters of this are equal to those in other .
false otherwise.

◆ fast_inequality_check()

static constexpr auto arene::base::string_view::fast_inequality_check ( string_view const first,
string_view const second ) -> inequality_heuristic
inlinestaticconstexprnoexcept

quick check that string views have the same size to quickly identify non-equal strings.

Parameters
firstThe first string_view to compare.
secondThe second string_view to compare.
Returns
inequality_heuristic inequality_heuristic::definitely_not_equal if the strings have different lengths, inequality_heuristic::may_be_equal_or_not_equal otherwise.

◆ find() [1/4]

auto arene::base::string_view::find ( character const chr,
size_type const pos = 0U ) const -> size_type
inlineconstexprnoexcept

Find the earliest position of the specified character within the string, starting at the specified position.

Parameters
chrThe character to search for.
posThe lowest position to search from. Defaults to 0.
Returns
The position of that character, or npos if not found

◆ find() [2/4]

auto arene::base::string_view::find ( raw_c_string const str,
size_type const pos,
size_type const n ) const -> size_type
inlineconstexprnoexcept

Find the earliest position of the n character string starting at str within the string, starting at the specified position.

Parameters
strThe start of the string to search for
posThe lowest position in this to search from
nThe length of the string to search for
Returns
Equivalent to find(string_view{str, n}, pos)
Precondition
str must be a pointer to a character array of at least n characters else behavior is undefined.

◆ find() [3/4]

auto arene::base::string_view::find ( raw_c_string const str,
size_type const pos = 0U ) const -> size_type
inlineconstexprnoexcept

Find the earliest position of the given substring within the string, starting at the specified position.

Parameters
strThe substring to search for
posThe lowest position to search from. Defaults to 0 .
Returns
The offset at which str can be found within the string, or npos if not found.
Precondition
str must be a null terminated string or else behavior is undefined.

◆ find() [4/4]

auto arene::base::string_view::find ( string_view const str,
size_type const pos = 0U ) const -> size_type
inlineconstexprnoexcept

Find the earliest position of the given substring within the string, starting at the specified position.

Parameters
strThe substring to search for
posThe lowest position to search from. Defaults to 0 .
Returns
The offset at which str can be found within the string, or npos if not found.

◆ find_first_not_of() [1/4]

auto arene::base::string_view::find_first_not_of ( character const chr,
size_type const pos = 0U ) const -> size_type
inlineconstexprnoexcept

Finds the first character not equal to the provided character.

Parameters
chrThe character to find
posThe start position to search from. Defaults to 0 .
Returns
The offset of the first character not matching chr if there is one, otherwise npos

◆ find_first_not_of() [2/4]

auto arene::base::string_view::find_first_not_of ( raw_c_string const str,
size_type const pos,
size_type const n ) const -> size_type
inlineconstexprnoexcept

Finds the first character not equal to any of the characters in the given character sequence.

Parameters
strThe list of characters to compare against.
posThe start position to search from in this .
nThe number of characters in str to consider.
Returns
The offset of the first character not in str after pos if there is one, otherwise npos
Precondition
str must be a pointer to a character array of at least n characters else behavior is undefined.

◆ find_first_not_of() [3/4]

auto arene::base::string_view::find_first_not_of ( raw_c_string const str,
size_type const pos = 0U ) const -> size_type
inlineconstexprnoexcept

Finds the first character not equal to any of the characters in the given character sequence.

Parameters
strThe list of characters to compare against.
posThe start position to search from. Defaults to 0 .
Returns
The offset of the first character not in str after pos if there is one, otherwise npos
Precondition
str must be a null terminated string or else behavior is undefined.

◆ find_first_not_of() [4/4]

auto arene::base::string_view::find_first_not_of ( string_view const str,
size_type const pos = 0U ) const -> size_type
inlineconstexprnoexcept

Finds the first character not equal to any of the characters in the given character sequence.

Parameters
strThe list of characters to compare against.
posThe start position to search from. Defaults to 0 .
Returns
The offset of the first character not in str after pos if there is one, otherwise npos

◆ find_first_of() [1/4]

auto arene::base::string_view::find_first_of ( character const chr,
size_type const pos = 0U ) const -> size_type
inlineconstexprnoexcept

Finds the first character equal to the specified character.

Parameters
chrThe character to find
posThe start position to search from. Defaults to 0 .
Returns
The offset of the first character in this that matches chr if there is one, otherwise npos

◆ find_first_of() [2/4]

auto arene::base::string_view::find_first_of ( raw_c_string const str,
size_type const pos,
size_type const n ) const -> size_type
inlineconstexprnoexcept

Finds the first character equal to any of the characters in the given character sequence.

Parameters
strThe list of characters to find any of.
posThe start position in this to search from.
nThe number of characters in str to consider.
Returns
The offset of the first character in str after pos if there is one, otherwise npos
Precondition
str must be a pointer to a character array of at least n characters else behavior is undefined.

◆ find_first_of() [3/4]

auto arene::base::string_view::find_first_of ( raw_c_string const str,
size_type const pos = 0U ) const -> size_type
inlineconstexprnoexcept

Finds the first character equal to any of the characters in the given character sequence.

Parameters
strThe list of characters to find any of
posThe start position to search from. Defaults to 0 .
Returns
The offset of the first character in this that matches any character in str if there is one, otherwise npos
Precondition
str must be a null terminated string or else behavior is undefined.

◆ find_first_of() [4/4]

auto arene::base::string_view::find_first_of ( string_view const str,
size_type const pos = 0U ) const -> size_type
inlineconstexprnoexcept

Finds the first character equal to any of the characters in the given character sequence.

Parameters
strThe list of characters to find any of
posThe start position to search from. Defaults to 0 .
Returns
The offset of the first character in this that matches any character in str if there is one, otherwise npos

◆ find_last_not_of() [1/4]

auto arene::base::string_view::find_last_not_of ( character const chr,
size_type const pos = npos ) const -> size_type
inlineconstexprnoexcept

Finds the last character equal to the provided character.

Parameters
chrThe character to find.
posThe highest position to search from. If pos >= size(), the search starts from the end of the string_view. Defaults to npos .
Returns
The offset of the last character not equal to chr if there is one, otherwise npos

◆ find_last_not_of() [2/4]

auto arene::base::string_view::find_last_not_of ( raw_c_string const str,
size_type const pos,
size_type const n ) const -> size_type
inlineconstexprnoexcept

Finds the last character not equal to any of the characters in the given character sequence.

Parameters
strThe list of characters to consider.
posThe highest position in this to search from. If pos >= size(), the search starts from the end of the string_view.
nThe number of characters in str to consider
Returns
The offset of the last character not in str at or before pos if there is one, otherwise npos
Precondition
str must be a pointer to a character array of at least n characters else behavior is undefined.

◆ find_last_not_of() [3/4]

auto arene::base::string_view::find_last_not_of ( raw_c_string const str,
size_type const pos = npos ) const -> size_type
inlineconstexprnoexcept

Finds the last character not equal to any of the characters in the given character sequence.

Parameters
strThe list of characters to consider.
posThe highest position to search from. If pos >= size(), the search starts from the end of the string_view. Defaults to npos
Returns
The offset of the last character not in str if there is one, otherwise npos
Precondition
str must be a null terminated string or else behavior is undefined.

◆ find_last_not_of() [4/4]

auto arene::base::string_view::find_last_not_of ( string_view const str,
size_type const pos = npos ) const -> size_type
inlineconstexprnoexcept

Finds the last character not equal to any of the characters in the given character sequence.

Parameters
strThe list of characters to consider.
posThe highest position to search from. If pos >= size(), the search starts from the end of the string_view. Defaults to npos
Returns
The offset of the last character not in str if there is one, otherwise npos

◆ find_last_of() [1/4]

auto arene::base::string_view::find_last_of ( character const chr,
size_type const pos = npos ) const -> size_type
inlineconstexprnoexcept

Finds the last character equal to the provided character.

Parameters
chrThe character to find.
posThe highest position to search from. If pos >= size(), the search starts from the end of the string_view.
Returns
The offset of the last character matching chr if there is one, otherwise npos

◆ find_last_of() [2/4]

auto arene::base::string_view::find_last_of ( raw_c_string const str,
size_type const pos,
size_type const n ) const -> size_type
inlineconstexprnoexcept

Finds the last character equal to one of characters in the given character sequence.

Parameters
strThe list of characters to compare against.
posThe highest position in this to search from. If pos >= size(), the search starts from the end of the string_view.
nThe number of characters in str to consider.
Returns
The offset of the last character matching any of the first n characters of str at or after pos if there is one, otherwise npos
Precondition
str must be a pointer to a character array of at least n characters else behavior is undefined.

◆ find_last_of() [3/4]

auto arene::base::string_view::find_last_of ( raw_c_string const str,
size_type const pos = npos ) const -> size_type
inlineconstexprnoexcept

Finds the last character equal to one of characters in the given character sequence.

Parameters
strThe list of characters to compare against.
posThe highest position to search from. If pos >= size(), the search starts from the end of the string_view. Defaults to npos .
Returns
The offset of the last character matching any of those in str if there is one, otherwise npos
Precondition
str must be a null terminated string or else behavior is undefined.

◆ find_last_of() [4/4]

auto arene::base::string_view::find_last_of ( string_view const str,
size_type const pos = npos ) const -> size_type
inlineconstexprnoexcept

Finds the last character equal to one of characters in the given character sequence.

Parameters
strThe list of characters to compare against.
posThe highest position to search from. If pos >= size(), the search starts from the end of the string_view. Defaults to npos .
Returns
The offset of the last character matching any of those in str if there is one, otherwise npos

◆ front()

auto arene::base::string_view::front ( ) const -> const_reference
inlineconstexprnoexcept

Get the first character in the string.

Returns
A reference to the first character
Precondition
empty() != false else ARENE_PRECONDITION violation

◆ length()

auto arene::base::string_view::length ( ) const -> size_type
inlineconstexprnoexcept

Get the length of the string view.

Returns
The number of 'char' values in this string.
Invariant
length() == std::distance(begin(), end())

◆ max_size()

static constexpr auto arene::base::string_view::max_size ( ) -> size_type
inlinestaticconstexprnoexcept

Get the maximum possible length of a string_view.

Returns
Return the maximum string size supported by a string_view

◆ operator std::string()

arene::base::string_view::operator std::string ( ) const

Implicit conversion to std::string. Provided since we cannot patch C++17's string_view constructor onto std::string.

◆ operator=() [1/2]

auto arene::base::string_view::operator= ( string_view && other) -> string_view &=default
constexprdefaultnoexcept

Move assignment operator for the string view.

Parameters
otherThe other string to move from
Returns
reference to the current string_view

◆ operator=() [2/2]

auto arene::base::string_view::operator= ( string_view const & other) -> string_view &=default
constexprdefaultnoexcept

Assignment operator for the string view.

Parameters
otherThe other string to assign from
Returns
reference to the current string_view

◆ operator[]()

auto arene::base::string_view::operator[] ( std::size_t pos) const -> const_reference
inlineconstexprnoexcept

Get a character at position pos in the string.

Parameters
posIndex of the character to access.
Returns
A reference to the character at pos position.
Precondition
pos < size() else ARENE_PRECONDITION violation

◆ rbegin()

auto arene::base::string_view::rbegin ( ) const -> reverse_iterator
inlineconstexprnoexcept

Obtain a reverse iterator referring to the end of the string.

Returns
An iterator that references the last character of the string_view.

◆ remove_prefix()

void arene::base::string_view::remove_prefix ( size_type const count)
inlineconstexprnoexcept

Remove the first n characters from the string.

Parameters
countthe number of characters to remove
Postcondition
The string_view will be equivalent to a substring produced as if by substr(n)

◆ remove_suffix()

void arene::base::string_view::remove_suffix ( size_type const count)
inlineconstexprnoexcept

Remove the last n characters from the string.

Parameters
countthe number of characters to remove
Postcondition
The string_view will be equivalent to a substring produced as if by substr(0, size() - std::min(count, size()))

◆ rend()

auto arene::base::string_view::rend ( ) const -> reverse_iterator
inlineconstexprnoexcept

Obtain a reverse iterator referring to one-before the front of the string_view.

Returns
An iterator that references one-before the first character of the string_view

◆ rfind() [1/4]

auto arene::base::string_view::rfind ( character const chr,
size_type const pos = npos ) const -> size_type
inlineconstexprnoexcept

Find the latest position of the specified character within the string, starting at the specified position.

Parameters
chrThe character to search for
posThe highest position to search from. If pos >= size(), the search starts from the end of the string_view.
Returns
The position of that character, or npos if not found

◆ rfind() [2/4]

auto arene::base::string_view::rfind ( raw_c_string const str,
size_type const pos,
size_type const n ) const -> size_type
inlineconstexprnoexcept

Find the latest position of the n character string starting at str within the string, starting at the specified position.

Parameters
strThe start of the string to search for
posThe highest position in this to search from. If pos >= size(), the search starts from the end of the string_view.
nThe length of the string to search for
Returns
The offset at which str can be found within the string, or npos if not found.
Precondition
str must be a pointer to a character array of at least n characters else behavior is undefined.

◆ rfind() [3/4]

auto arene::base::string_view::rfind ( raw_c_string const str,
size_type const pos = npos ) const -> size_type
inlineconstexprnoexcept

Find the latest position of the given substring within the string, starting at the specified position.

Parameters
strThe substring to search for
posThe highest position to search from. If pos >= size(), the search starts from the end of the string_view.
Returns
The offset at which str can be found within the string, or npos if not found.
Precondition
str must be a null terminated string or else behavior is undefined.

◆ rfind() [4/4]

auto arene::base::string_view::rfind ( string_view const str,
size_type const pos = npos ) const -> size_type
inlineconstexprnoexcept

Find the latest position of the given substring within the string, starting at the specified position.

Parameters
strThe substring to search for
posThe highest position to search from. If pos >= size(), the search starts from the end of the string_view.
Returns
The offset at which str can be found within the string, or npos if not found.

◆ size()

auto arene::base::string_view::size ( ) const -> size_type
inlineconstexprnoexcept

Get the length of the string view.

Returns
The number of 'char' values in this string.
Invariant
size() == std::distance(begin(), end())

◆ starts_with() [1/3]

auto arene::base::string_view::starts_with ( character const chr) const -> bool
inlineconstexprnoexcept

Check if the string starts with a specific character.

Parameters
chrThe character to check
Returns
true if the string is not empty and the first character is c
false otherwise.

◆ starts_with() [2/3]

auto arene::base::string_view::starts_with ( raw_c_string const other) const -> bool
inlineconstexprnoexcept

Check if the string starts with another string.

Parameters
otherThe string to compare against.
Returns
true if the first string_length(other) characters of this are equal to those in other .
false otherwise.
Precondition
other must be a null terminated string or else behavior is undefined.

◆ starts_with() [3/3]

auto arene::base::string_view::starts_with ( string_view const other) const -> bool
inlineconstexprnoexcept

Check if the string starts with another string.

Parameters
otherThe string to compare against.
Returns
true if the first other.size() characters of this are equal to those in other .
false otherwise.

◆ substr() [1/2]

auto arene::base::string_view::substr ( ) const -> string_view
inlineconstexprnoexcept

Create a new string view referencing the same string as *this.

Returns
A copy of *this

◆ substr() [2/2]

auto arene::base::string_view::substr ( size_type const pos,
size_type const count = npos ) const -> string_view
inlineconstexprnoexcept

Create a new string view based on a substring of the current one.

Parameters
posPosition of the first character of the substring.
countThe requested length of the substring.
Returns
string_view Will contain content beginning at pos and continuing for count characters. If pos>=size() , or pos+count>=size() , the returned substring is clamped to the end of the string_view .

◆ swap()

void arene::base::string_view::swap ( string_view & other)
inlineconstexprnoexcept

Swap the content of two string_view objects.

Parameters
otherThe other string_view to swap with.

◆ three_way_compare()

static constexpr auto arene::base::string_view::three_way_compare ( string_view const lhs,
string_view const rhs ) -> strong_ordering
inlinestaticconstexprnoexcept

Compare two string_view objects lexicographically.

Parameters
lhsThe first string to compare
rhsThe second string to compare
Returns
strong_ordering::equal if the length of lhs and rhs are equal and all characters compare equal.
strong_ordering::less if the value of the first character that does not match is lexicographically less in lhs than rhs.
strong_ordering::less if the length of lhs is less than the length of rhs and all characters in the overlapping subset of rhs match those in lhs.
strong_ordering::greater if the value of the first character that does not match is lexicographically greater in lhs than rhs.
strong_ordering::greater if the length of lhs is greater than the length of rhs and all characters in the overlapping subset of lhs match those in rhs.

Member Data Documentation

◆ npos

std::size_t arene::base::string_view::npos {std::numeric_limits<std::size_t>::max()}
staticconstexpr

Special marker value for end of string.


The documentation for this class was generated from the following file: