28 #ifndef BSL_BASIC_STRING_VIEW_HPP 29 #define BSL_BASIC_STRING_VIEW_HPP 59 template<
typename CharT,
typename Traits =
char_traits<CharT>>
122 : m_ptr{s}, m_count{Traits::length(s)}
124 if ((
nullptr == m_ptr) || (0U == m_count)) {
168 if ((
nullptr == m_ptr) || (index >= m_count)) {
172 return &m_ptr[index];
190 if ((
nullptr == m_ptr) || (index >= m_count)) {
194 return &m_ptr[index];
211 return this->
at_if(0U);
228 return this->
at_if(0U);
245 return this->
at_if((m_count > 0U) ? (m_count - 1U) : 0U);
262 return this->
at_if((m_count > 0U) ? (m_count - 1U) : 0U);
505 size_type const ai{(i >= m_count) ? m_count : (i + 1U)};
526 size_type const ai{(i >= m_count) ? m_count : (i + 1U)};
547 size_type const ai{(i >= m_count) ? m_count : (i + 1U)};
615 [[nodiscard]] constexpr
bool 618 return 0U == m_count;
678 return m_count *
sizeof(CharT);
695 if (n >= this->
size()) {
717 if (n >= this->
size()) {
747 if (pos >= this->
size()) {
765 return Traits::compare(this->
data(), str.data(),
min_of(this->
size(), str.size()));
807 return this->
substr(pos1, count1).
compare(str.substr(pos2, count2));
876 [[nodiscard]] constexpr
bool 879 if (this->
size() < str.size()) {
883 return this->
substr(0U, str.size()) == str;
895 [[nodiscard]] constexpr
bool 898 if (
auto *
const ptr = this->
front_if()) {
899 return Traits::eq(*ptr, c);
914 [[nodiscard]] constexpr
bool 929 [[nodiscard]] constexpr
bool 932 if (this->
size() < str.size()) {
948 [[nodiscard]] constexpr
bool 951 if (
auto *
const ptr = this->
back_if()) {
952 return Traits::eq(*ptr, c);
967 [[nodiscard]] constexpr
bool 985 : m_ptr{s}, m_count{count}
987 if ((
nullptr == m_ptr) || (0U == m_count)) {
1016 template<
typename CharT,
typename Traits>
1022 if (lhs.size() != rhs.size()) {
1026 return lhs.compare(rhs) == 0;
1047 template<
typename CharT,
typename Traits>
1072 template<
typename CharT,
typename Traits>
1097 template<
typename CharT,
typename Traits>
1103 return !(lhs == rhs);
1124 template<
typename CharT,
typename Traits>
1128 return !(lhs == rhs);
1149 template<
typename CharT,
typename Traits>
1153 return !(lhs == rhs);
1169 template<
typename OUT,
typename CharT>
1173 details::fmt_impl_align_pre(o, ops, str.length(),
true);
1174 o.write(str.data());
1175 details::fmt_impl_align_suf(o, ops, str.length(),
true);
1189 template<
typename T,
typename CharT>
1190 [[maybe_unused]] constexpr out<T>
1193 if constexpr (o.empty()) {
1197 o.write(str.data());
constexpr bool empty() const noexcept
Returns size() == 0.
Definition: basic_string_view.hpp:616
constexpr reverse_iterator_type rend() noexcept
Returns a reverse iterator first element of the view. When accessing the iterator,...
Definition: basic_string_view.hpp:565
constexpr bool starts_with(value_type const c) const noexcept
Checks if the string begins with the given prefix.
Definition: basic_string_view.hpp:896
constexpr pointer_type back_if() noexcept
Returns a pointer to the instance of T stored at index "size() - 1". If the index is out of bounds,...
Definition: basic_string_view.hpp:243
constexpr bsl::uintmax npos
defines npos
Definition: npos.hpp:37
constexpr const_pointer_type front_if() const noexcept
Returns a pointer to the instance of T stored at index "0". If the index is out of bounds,...
Definition: basic_string_view.hpp:226
constexpr pointer_type data() noexcept
Returns a pointer to the string being viewed. If this is a default constructed view,...
Definition: basic_string_view.hpp:277
constexpr bool operator!=(bsl::basic_string_view< CharT, Traits > const &lhs, CharT const *const rhs) noexcept
Returns true if two strings are not the same length (which is different from compare() which uses the...
Definition: basic_string_view.hpp:1126
constexpr bsl::int32 compare(size_type const pos, size_type const count, basic_string_view const &str) const noexcept
Same as substr(pos, count).compare(v)
Definition: basic_string_view.hpp:779
constexpr basic_string_view & remove_prefix(size_type const n) noexcept
Moves the start of the view forward by n characters. If n >= size(), the bsl::basic_string_view is re...
Definition: basic_string_view.hpp:693
reverse_iterator< iterator_type > reverse_iterator_type
alias for: reverse_iterator<iterator>
Definition: basic_string_view.hpp:82
constexpr const_reverse_iterator_type rend() const noexcept
Returns a reverse iterator first element of the view. When accessing the iterator,...
Definition: basic_string_view.hpp:584
constexpr iterator_type iter(size_type const i) noexcept
Returns an iterator to the element "i" in the view.
Definition: basic_string_view.hpp:347
constexpr const_reverse_iterator_type rbegin() const noexcept
Returns a reverse iterator to one past the last element of the view. When accessing the iterator,...
Definition: basic_string_view.hpp:464
A bsl::basic_string_view is a non-owning, encapsulation of a string, providing helper functions for w...
Definition: basic_string_view.hpp:60
constexpr bool operator!=(bsl::basic_string_view< CharT, Traits > const &lhs, bsl::basic_string_view< CharT, Traits > const &rhs) noexcept
Returns true if two strings are not the same length (which is different from compare() which uses the...
Definition: basic_string_view.hpp:1099
constexpr bool operator==(bsl::basic_string_view< CharT, Traits > const &lhs, bsl::basic_string_view< CharT, Traits > const &rhs) noexcept
Returns true if two strings have the same length (which is different from compare() which uses the mi...
Definition: basic_string_view.hpp:1018
constexpr const_iterator_type citer(size_type const i) const noexcept
Returns an iterator to the element "i" in the view.
Definition: basic_string_view.hpp:375
Used by fmt to determine how to format the output of an fmt command. See the documentation fo bsl::fm...
Definition: fmt_options.hpp:141
constexpr basic_string_view() noexcept=default
Default constructor that creates a basic_string_view with data() == nullptr and size() == 0....
constexpr iterator_type end() noexcept
Returns an iterator to one past the last element of the view. If you attempt to access this iterator,...
Definition: basic_string_view.hpp:392
constexpr const_iterator_type iter(size_type const i) const noexcept
Returns an iterator to the element "i" in the view.
Definition: basic_string_view.hpp:361
constexpr reverse_iterator_type rbegin() noexcept
Returns a reverse iterator to one past the last element of the view. When accessing the iterator,...
Definition: basic_string_view.hpp:445
CharT const * const_pointer_type
alias for: CharT const const *
Definition: basic_string_view.hpp:76
contiguous_iterator< CharT const > iterator_type
alias for: contiguous_iterator<CharT const>
Definition: basic_string_view.hpp:78
constexpr const_reverse_iterator_type riter(size_type const i) const noexcept
Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will al...
Definition: basic_string_view.hpp:524
constexpr basic_string_view & remove_suffix(size_type const n) noexcept
Moves the end of the view back by n characters. If n >= size(), the bsl::basic_string_view is reset t...
Definition: basic_string_view.hpp:715
constexpr iterator_type begin() noexcept
Returns an iterator to the first element of the view.
Definition: basic_string_view.hpp:307
constexpr pointer_type front_if() noexcept
Returns a pointer to the instance of T stored at index "0". If the index is out of bounds,...
Definition: basic_string_view.hpp:209
constexpr const_iterator_type cbegin() const noexcept
Returns an iterator to the first element of the view.
Definition: basic_string_view.hpp:333
constexpr const_reverse_iterator_type crend() const noexcept
Returns a reverse iterator first element of the view. When accessing the iterator,...
Definition: basic_string_view.hpp:603
static constexpr size_type max_size() noexcept
Returns the max number of elements the BSL supports.
Definition: basic_string_view.hpp:663
constexpr bsl::int32 compare(size_type pos1, size_type count1, basic_string_view const &str, size_type pos2, size_type count2) const noexcept
Same as substr(pos1, count1).compare(v.substr(pos2, count2))
Definition: basic_string_view.hpp:800
constexpr bool operator==(bsl::basic_string_view< CharT, Traits > const &lhs, CharT const *const rhs) noexcept
Returns true if two strings have the same length (which is different from compare() which uses the mi...
Definition: basic_string_view.hpp:1049
CharT const value_type
alias for: CharT const
Definition: basic_string_view.hpp:64
constexpr const_pointer_type back_if() const noexcept
Returns a pointer to the instance of T stored at index "size() - 1". If the index is out of bounds,...
Definition: basic_string_view.hpp:260
constexpr bool operator==(CharT const *const lhs, bsl::basic_string_view< CharT, Traits > const &rhs) noexcept
Returns true if two strings have the same length (which is different from compare() which uses the mi...
Definition: basic_string_view.hpp:1074
constexpr bool operator!=(CharT const *const lhs, bsl::basic_string_view< CharT, Traits > const &rhs) noexcept
Returns true if two strings are not the same length (which is different from compare() which uses the...
Definition: basic_string_view.hpp:1151
constexpr bool ends_with(value_type const c) const noexcept
Checks if the string ends with the given suffix.
Definition: basic_string_view.hpp:949
constexpr const_reverse_iterator_type crbegin() const noexcept
Returns a reverse iterator to one past the last element of the view. When accessing the iterator,...
Definition: basic_string_view.hpp:483
constexpr size_type length() const noexcept
Returns the length of the string being viewed. This is the same as bsl::basic_string_view::size()....
Definition: basic_string_view.hpp:650
bsl::uintmax difference_type
alias for: bsl::uintmax
Definition: basic_string_view.hpp:68
static constexpr T max() noexcept
Returns the max value of T.
Definition: numeric_limits.hpp:154
constexpr basic_string_view & operator=(pointer_type const s) &noexcept
ptr assignment. This assigns a bsl::basic_string_view a pointer to a string. The number of characters...
Definition: basic_string_view.hpp:141
constexpr bsl::int32 compare(size_type pos, size_type count, pointer_type const str) const noexcept
Same as substr(pos, count).compare(basic_string_view{s})
Definition: basic_string_view.hpp:835
constexpr const_pointer_type data() const noexcept
Returns a pointer to the string being viewed. If this is a default constructed view,...
Definition: basic_string_view.hpp:294
constexpr const_iterator_type begin() const noexcept
Returns an iterator to the first element of the view.
Definition: basic_string_view.hpp:320
constexpr pointer_type at_if(size_type const index) noexcept
Returns a pointer to the instance of T stored at index "index". If the index is out of bounds,...
Definition: basic_string_view.hpp:166
CharT const & reference_type
alias for: CharT const &
Definition: basic_string_view.hpp:70
Provides a reverse iterator as defined by the C++ specification, with the follwing differences:
Definition: reverse_iterator.hpp:78
constexpr bool starts_with(basic_string_view const &str) const noexcept
Checks if the string begins with the given prefix.
Definition: basic_string_view.hpp:877
constexpr bool starts_with(pointer_type const str) const noexcept
Checks if the string begins with the given prefix.
Definition: basic_string_view.hpp:915
::int32_t int32
defines an 32bit signed integer
Definition: cstdint.hpp:40
constexpr size_type size_bytes() const noexcept
Returns size() * sizeof(T)
Definition: basic_string_view.hpp:676
constexpr const_reverse_iterator_type criter(size_type const i) const noexcept
Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will al...
Definition: basic_string_view.hpp:545
constexpr bool ends_with(pointer_type const str) const noexcept
Checks if the string ends with the given suffix.
Definition: basic_string_view.hpp:968
constexpr const_iterator_type end() const noexcept
Returns an iterator to one past the last element of the view. If you attempt to access this iterator,...
Definition: basic_string_view.hpp:409
constexpr bsl::int32 compare(basic_string_view const &str) const noexcept
Compares two strings.
Definition: basic_string_view.hpp:763
constexpr const_iterator_type cend() const noexcept
Returns an iterator to one past the last element of the view. If you attempt to access this iterator,...
Definition: basic_string_view.hpp:426
constexpr size_type size() const noexcept
Returns the number of elements in the string being viewed. If this is a default constructed view,...
Definition: basic_string_view.hpp:633
constexpr const_pointer_type at_if(size_type const index) const noexcept
Returns a pointer to the instance of T stored at index "index". If the index is out of bounds,...
Definition: basic_string_view.hpp:188
constexpr basic_string_view substr(size_type const pos=0U, size_type const count=npos) const noexcept
Returns a new bsl::basic_string_view that is a substring view of the original. The substring starts a...
Definition: basic_string_view.hpp:745
constexpr bool ends_with(basic_string_view const &str) const noexcept
Checks if the string ends with the given suffix.
Definition: basic_string_view.hpp:930
CharT const & const_reference_type
alias for: CharT const &
Definition: basic_string_view.hpp:72
contiguous_iterator< CharT const > const_iterator_type
alias for: contiguous_iterator<CharT const const>
Definition: basic_string_view.hpp:80
CharT const * pointer_type
alias for: CharT const *
Definition: basic_string_view.hpp:74
constexpr bsl::int32 compare(pointer_type const str) const noexcept
Same as compare(basic_string_view{s})
Definition: basic_string_view.hpp:819
reverse_iterator< const_iterator_type > const_reverse_iterator_type
alias for: reverse_iterator<const_iterator>
Definition: basic_string_view.hpp:84
constexpr void fmt_impl(OUT &&o, fmt_options const &ops, basic_string_view< CharT > const &str) noexcept
This function is responsible for implementing bsl::fmt for string_view types. For strings,...
Definition: basic_string_view.hpp:1171
constexpr reverse_iterator_type riter(size_type const i) noexcept
Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will al...
Definition: basic_string_view.hpp:503
constexpr T const & min_of(T const &a, T const &b) noexcept
Returns a if a is smaller than b, otherwise returns b. Note that this function is called min_of to pr...
Definition: min_of.hpp:47
::uintmax_t uintmax
defines a unsigned integer with the maximum possible size
Definition: cstdint.hpp:97
constexpr bsl::int32 compare(size_type pos, size_type count1, pointer_type const str, size_type count2) const noexcept
Same as substr(pos, count1).compare(basic_string_view{s, count2})
Definition: basic_string_view.hpp:858
bsl::uintmax size_type
alias for: bsl::uintmax
Definition: basic_string_view.hpp:66
Provides a contiguous iterator as defined by the C++ specification, with the follwing differences:
Definition: contiguous_iterator.hpp:76