bn::string_view class

Refers to a constant contiguous sequence of char values.

It doesn't store the char data like a string does.

Public types

using value_type = char
Value type alias.
using size_type = int
Size type alias.
using difference_type = int
Difference type alias.
using reference = char&
Reference alias.
using const_reference = const char&
Const reference alias.
using pointer = char*
Pointer alias.
using const_pointer = const char*
Const pointer alias.
using iterator = char*
Iterator alias.
using const_iterator = const char*
Const iterator alias.
using reverse_iterator = bn::reverse_iterator<iterator>
Reverse iterator alias.
using const_reverse_iterator = bn::reverse_iterator<const_iterator>
Const reverse iterator alias.

Public static variables

static size_type npos constexpr
Exact meaning depends on context.

Constructors, destructors, conversion operators

string_view() defaulted constexpr
Default constructor.
string_view(const istring_base& string) constexpr
Constructor.
string_view(const_pointer char_array_ptr) constexpr
Constructor.
string_view(const_pointer char_array_ptr, size_type char_array_size) constexpr
Constructor.

Public functions

auto front() const -> const_reference constexpr
Returns a const reference to the first character.
auto back() const -> const_reference constexpr
Returns a const reference to the last character.
auto data() const -> const_pointer constexpr
Returns a const pointer to the first character of the internal storage.
auto begin() const -> const_iterator constexpr
Returns a const iterator to the beginning of the string_view.
auto cbegin() const -> const_iterator constexpr
Returns a const iterator to the beginning of the string_view.
auto end() const -> const_iterator constexpr
Returns a const iterator to the end of the string_view.
auto cend() const -> const_iterator constexpr
Returns a const iterator to the end of the string_view.
auto rbegin() const -> const_reverse_iterator constexpr
Returns a const reverse iterator to the end of the string_view.
auto crbegin() const -> const_reverse_iterator constexpr
Returns a const reverse iterator to the end of the string_view.
auto rend() const -> const_reverse_iterator constexpr
Returns a const reverse iterator to the beginning of the string_view.
auto crend() const -> const_reverse_iterator constexpr
Returns a const reverse iterator to the beginning of the string_view.
auto empty() const -> bool constexpr
Indicates if it doesn't contain any character.
auto size() const -> size_type constexpr
Returns the number of characters in the string_view.
auto length() const -> size_type constexpr
Returns the number of characters in the string_view.
auto operator[](size_type position) const -> const_reference constexpr
Returns a const reference to the character at the specified location.
auto at(size_type position) const -> const_reference constexpr
Returns a const reference to the character at the specified location.
auto substr() const -> string_view constexpr
Returns a copy of this.
auto substr(size_type position) const -> string_view constexpr
Returns a string_view of the substring [position, size() - position).
auto substr(size_type position, size_type count) const -> string_view constexpr
Returns a string_view of the substring [position, position + count).
void remove_prefix(size_type count) constexpr
Shrinks the string_view by moving its start forward by count characters.
void remove_suffix(size_type count) constexpr
Shrinks the string_view by moving its end backward by count characters.
auto starts_with(value_type value) const -> bool constexpr
Checks if the referenced string begins with the given prefix.
auto starts_with(const string_view& other) const -> bool constexpr
Checks if the referenced string begins with the given prefix.
auto starts_with(const_pointer char_array_ptr) const -> bool constexpr
Checks if the referenced string begins with the given prefix.
auto ends_with(value_type value) const -> bool constexpr
Checks if the referenced string ends with the given prefix.
auto ends_with(const string_view& other) const -> bool constexpr
Checks if the referenced string ends with the given prefix.
auto ends_with(const_pointer char_array_ptr) const -> bool constexpr
Checks if the referenced string ends with the given prefix.
auto contains(value_type value) const -> bool constexpr
Checks if the referenced string contains the given character.
auto contains(const string_view& other) const -> bool constexpr
Checks if the referenced string contains the given substring.
auto contains(const_pointer char_array_ptr) const -> bool constexpr
Checks if the referenced string contains the given substring.
auto find(value_type value) const -> size_type constexpr
Finds the first substring equal to the given character.
auto find(const string_view& other) const -> size_type constexpr
Finds the first substring equal to the given character sequence.
auto find(const_pointer char_array_ptr) const -> size_type constexpr
Finds the first substring equal to the given character sequence.
void swap(string_view& other) constexpr
Exchanges the contents of this string_view with those of the other one.

Friends

void swap(string_view& a, string_view& b) constexpr
Exchanges the contents of a string_view with those of another one.
auto operator==(const string_view& a, const string_view& b) -> bool constexpr
Equal operator.
auto operator<(const string_view& a, const string_view& b) -> bool constexpr
Less than operator.
auto operator>(const string_view& a, const string_view& b) -> bool constexpr
Greater than operator.
auto operator<=(const string_view& a, const string_view& b) -> bool constexpr
Less than or equal operator.
auto operator>=(const string_view& a, const string_view& b) -> bool constexpr
Greater than or equal operator.

Function documentation

bn::string_view::string_view(const istring_base& string) constexpr

Constructor.

Parameters
string Base string to reference.

bn::string_view::string_view(const_pointer char_array_ptr) constexpr

Constructor.

Parameters
char_array_ptr Pointer to null-terminated characters array.

bn::string_view::string_view(const_pointer char_array_ptr, size_type char_array_size) constexpr

Constructor.

Parameters
char_array_ptr Pointer to characters array.
char_array_size Characters count of the characters array.

const_reference bn::string_view::operator[](size_type position) const constexpr

Returns a const reference to the character at the specified location.

Parameters
position Character's position index.
Returns Const reference to the character at the specified location.

const_reference bn::string_view::at(size_type position) const constexpr

Returns a const reference to the character at the specified location.

Parameters
position Character's position index.
Returns Const reference to the character at the specified location.

bool bn::string_view::starts_with(value_type value) const constexpr

Checks if the referenced string begins with the given prefix.

Parameters
value Single character.
Returns true if the referenced string begins with the given prefix; false otherwise.

bool bn::string_view::starts_with(const string_view& other) const constexpr

Checks if the referenced string begins with the given prefix.

Parameters
other Another string_view.
Returns true if the referenced string begins with the given prefix; false otherwise.

bool bn::string_view::starts_with(const_pointer char_array_ptr) const constexpr

Checks if the referenced string begins with the given prefix.

Parameters
char_array_ptr Pointer to null-terminated characters array.
Returns true if the referenced string begins with the given prefix; false otherwise.

bool bn::string_view::ends_with(value_type value) const constexpr

Checks if the referenced string ends with the given prefix.

Parameters
value Single character.
Returns true if the referenced string ends with the given prefix; false otherwise.

bool bn::string_view::ends_with(const string_view& other) const constexpr

Checks if the referenced string ends with the given prefix.

Parameters
other Another string_view.
Returns true if the referenced string ends with the given prefix; false otherwise.

bool bn::string_view::ends_with(const_pointer char_array_ptr) const constexpr

Checks if the referenced string ends with the given prefix.

Parameters
char_array_ptr Pointer to null-terminated characters array.
Returns true if the referenced string ends with the given prefix; false otherwise.

bool bn::string_view::contains(value_type value) const constexpr

Checks if the referenced string contains the given character.

Parameters
value Single character.
Returns true if the referenced string contains the given character; false otherwise.

bool bn::string_view::contains(const string_view& other) const constexpr

Checks if the referenced string contains the given substring.

Parameters
other Another string_view.
Returns true if the referenced string contains the given substring; false otherwise.

bool bn::string_view::contains(const_pointer char_array_ptr) const constexpr

Checks if the referenced string contains the given substring.

Parameters
char_array_ptr Pointer to null-terminated characters array.
Returns true if the referenced string contains the given substring; false otherwise.

size_type bn::string_view::find(value_type value) const constexpr

Finds the first substring equal to the given character.

Parameters
value Single character.
Returns Position of the first character of the found substring, or npos if no such substring is found.

size_type bn::string_view::find(const string_view& other) const constexpr

Finds the first substring equal to the given character sequence.

Parameters
other Another string_view.
Returns Position of the first character of the found substring, or npos if no such substring is found.

size_type bn::string_view::find(const_pointer char_array_ptr) const constexpr

Finds the first substring equal to the given character sequence.

Parameters
char_array_ptr Pointer to null-terminated characters array.
Returns Position of the first character of the found substring, or npos if no such substring is found.

void bn::string_view::swap(string_view& other) constexpr

Exchanges the contents of this string_view with those of the other one.

Parameters
other string_view to exchange the contents with.

void swap(string_view& a, string_view& b) constexpr

Exchanges the contents of a string_view with those of another one.

Parameters
a First string_view to exchange the contents with.
b Second string_view to exchange the contents with.

bool operator==(const string_view& a, const string_view& b) constexpr

Equal operator.

Parameters
a First string_view to compare.
b Second string_view to compare.
Returns true if the first string_view is equal to the second one, otherwise false.

bool operator<(const string_view& a, const string_view& b) constexpr

Less than operator.

Parameters
a First string_view to compare.
b Second string_view to compare.
Returns true if the first string_view is lexicographically less than the second one, otherwise false.

bool operator>(const string_view& a, const string_view& b) constexpr

Greater than operator.

Parameters
a First string_view to compare.
b Second string_view to compare.
Returns true if the first string_view is lexicographically greater than the second one, otherwise false.

bool operator<=(const string_view& a, const string_view& b) constexpr

Less than or equal operator.

Parameters
a First string_view to compare.
b Second string_view to compare.
Returns true if the first string_view is lexicographically less than or equal to the second one, otherwise false.

bool operator>=(const string_view& a, const string_view& b) constexpr

Greater than or equal operator.

Parameters
a First string_view to compare.
b Second string_view to compare.
Returns true if the first string_view is lexicographically greater than or equal to the second one, otherwise false.