5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_STRINGS_NULL_TERMINATED_STRING_VIEW_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_STRINGS_NULL_TERMINATED_STRING_VIEW_HPP_
19#include "arene/base/detail/raw_c_string.hpp"
20#include "arene/base/detail/wrapped_iterator.hpp"
24#include "arene/base/stdlib_choice/cstddef.hpp"
25#include "arene/base/stdlib_choice/enable_if.hpp"
26#include "arene/base/stdlib_choice/integral_constant.hpp"
27#include "arene/base/stdlib_choice/is_same.hpp"
28#include "arene/base/stdlib_choice/string.hpp"
29#include "arene/base/strings/detail/lexicographic_string_compare.hpp"
30#include "arene/base/strings/detail/string_length.hpp"
31#include "arene/base/strings/detail/string_view_ostream_mixin.hpp"
62 , string_view_ostream_mixin<null_terminated_string_view> {
67 constexpr explicit passkey() =
default;
75 using integral_comparison_result = int;
127 template <typename String, constraints<std::enable_if_t<std::is_same<String, std::string>::value>> =
nullptr>
131 string_(
string.
c_str()) {}
149 using const_iterator = ::arene::base::detail::wrapped_iterator<const_pointer, passkey>;
165 return *iter.base() ==
'\0';
296 template <typename String, constraints<std::enable_if_t<std::is_same<String, std::string>::value>> =
nullptr>
297 auto compare(String
const& other)
const noexcept -> integral_comparison_result {
313 return detail::lexicographic_string_compare(lhs.c_str(), rhs.c_str());
324 static constexpr auto
340 template <typename String, constraints<std::enable_if_t<std::is_same<String, std::string>::value>> =
nullptr>
355 return opposite_ordering(detail::lexicographic_string_compare({rhs.data(), rhs.size()}, lhs.c_str()));
360 detail::raw_c_string string_;
376 detail::raw_c_string start{string_};
377 while ((offset != 0U) && (*start !=
'\0')) {
379 arene::base::advance(start, 1);
413 auto first =
begin();
414 while ((offset != 0U) && (first !=
end())) {
420 while ((max_length != 0U) && (last !=
end())) {
425 return {first.base(),
static_cast<std::size_t>(last - first)};
441constexpr auto operator""_ntsv(detail::raw_c_string
const str,
std::size_t )
noexcept
Provides a backport of C++17's constexpr std::advance.
constexpr generic_ordering_from_three_way_compare() noexcept=default
This type represents the sentinel of the range of characters.
Definition null_terminated_string_view.hpp:136
A read-only string-view that provides a view onto a null-terminated string.
Definition null_terminated_string_view.hpp:62
~null_terminated_string_view()=default
default destructor
static ARENE_NODISCARD constexpr auto end() noexcept -> sentinel
Get the sentinel (end-iterator) of this string.
Definition null_terminated_string_view.hpp:195
::arene::base::detail::wrapped_iterator< const_pointer, passkey > const_iterator
The type of const iterator used by this view.
Definition null_terminated_string_view.hpp:149
value_type const * const_pointer
The const pointer type of this view.
Definition null_terminated_string_view.hpp:143
value_type * pointer
The pointer type of this view.
Definition null_terminated_string_view.hpp:141
constexpr auto compare(string_view const &other) const noexcept -> integral_comparison_result
Compare this null-terminated string to a string_view.
Definition null_terminated_string_view.hpp:283
null_terminated_string_view(std::nullptr_t)=delete
constructing from a nullptr literal is always an error.
null_terminated_string_view(String const &string) noexcept
Implicit construction from a std::string (which is required to be null-terminated).
Definition null_terminated_string_view.hpp:129
static constexpr auto three_way_compare(null_terminated_string_view const lhs, string_view const rhs) noexcept -> strong_ordering
Compare a null-terminated string to a string_view.
Definition null_terminated_string_view.hpp:353
detail::character value_type
The value type of this view.
Definition null_terminated_string_view.hpp:139
ARENE_NODISCARD constexpr auto size() const noexcept -> size_type
Query the length of the string.
Definition null_terminated_string_view.hpp:219
constexpr auto operator=(null_terminated_string_view const &) -> null_terminated_string_view &=default
default copy assignment
ARENE_NODISCARD constexpr auto data() const noexcept -> const_pointer
Obtain a C-style null-terminated string pointer.
Definition null_terminated_string_view.hpp:228
value_type & reference
The type of a reference to an element in the view.
Definition null_terminated_string_view.hpp:145
const_iterator iterator
The type of iterator used by this view.
Definition null_terminated_string_view.hpp:151
ARENE_NODISCARD friend constexpr auto operator!=(iterator const iter, sentinel) noexcept -> bool
Equality comparison for a null terminated string view's iterator and the end-of-string sentinel.
Definition null_terminated_string_view.hpp:177
constexpr auto operator=(null_terminated_string_view &&) -> null_terminated_string_view &=default
default move assignment
ARENE_NODISCARD constexpr auto length() const noexcept -> size_type
Query the length of the string.
Definition null_terminated_string_view.hpp:209
constexpr null_terminated_string_view(null_terminated_string_view &&)=default
default move constructor
typename iterator::difference_type difference_type
The type used for differences between iterators in this view.
Definition null_terminated_string_view.hpp:155
ARENE_NODISCARD constexpr auto c_str() const noexcept -> const_pointer
Obtain a C-style null-terminated string pointer.
Definition null_terminated_string_view.hpp:224
auto compare(String const &other) const noexcept -> integral_comparison_result
Compare this null-terminated string to a std::string.
Definition null_terminated_string_view.hpp:297
value_type const & const_reference
The type of a reference to an element in the view.
Definition null_terminated_string_view.hpp:147
ARENE_NODISCARD constexpr auto substr(std::size_t offset) const noexcept -> null_terminated_string_view
Compute the sub-string starting at the specified offset within the string.
Definition null_terminated_string_view.hpp:374
ARENE_NODISCARD constexpr auto empty() const noexcept -> bool
Query if this string is the empty string.
Definition null_terminated_string_view.hpp:200
static constexpr auto three_way_compare(null_terminated_string_view const lhs, null_terminated_string_view const rhs) noexcept -> strong_ordering
Compare two null-terminated strings.
Definition null_terminated_string_view.hpp:309
static constexpr auto three_way_compare(null_terminated_string_view const lhs, detail::raw_c_string const rhs) noexcept -> strong_ordering
Compare two null-terminated strings.
Definition null_terminated_string_view.hpp:325
constexpr null_terminated_string_view() noexcept
construct an empty string-view.
Definition null_terminated_string_view.hpp:82
constexpr auto compare(null_terminated_string_view const other) const noexcept -> integral_comparison_result
Compare this null-terminated string to another null-terminated string.
Definition null_terminated_string_view.hpp:272
ARENE_NODISCARD constexpr auto begin() const noexcept -> const_iterator
Get an iterator to the first element of the string.
Definition null_terminated_string_view.hpp:186
std::size_t size_type
The type used for sizes in this view.
Definition null_terminated_string_view.hpp:153
constexpr null_terminated_string_view(null_terminated_string_view const &)=default
default copy constructor
ARENE_NODISCARD friend constexpr auto operator==(iterator const iter, sentinel) noexcept -> bool
Equality comparison for a null terminated string view's iterator and the end-of-string sentinel.
Definition null_terminated_string_view.hpp:164
static auto three_way_compare(null_terminated_string_view const lhs, String const &rhs) noexcept -> strong_ordering
Compare a null-terminated string to a std::string.
Definition null_terminated_string_view.hpp:341
An opt-in trait to indicate that a range type is a borrowed range.
Definition enable_borrowed_range.hpp:31
Backport of the C++17 std::string_view class.
Definition string_view.hpp:54
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Definition accumulate.hpp:37
strong_ordering_detail::strong_ordering strong_ordering
The enumeration specifying the result of an ordering comparison.
Definition strong_ordering.hpp:147
constexpr auto opposite_ordering(strong_ordering const ordering) noexcept -> strong_ordering
Return the opposite ordering for a strong_ordering three-way-comparison result.
Definition strong_ordering.hpp:209
constexpr auto from_strong_ordering(strong_ordering const ordering) noexcept -> int
Convert a strong_ordering into an integer three-way-comparison result.
Definition strong_ordering.hpp:177
Definition accumulate.hpp:36
typedef nullptr_t
The type of nullptr.
Definition cstddef.hpp:33
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
bool_constant< true > true_type
An alias for bool_constant<true>
Definition integral_constant.hpp:76
#define ARENE_NODISCARD
An alias for [[nodiscard]] , or a no-op if the attribute is not supported.
Definition nodiscard.hpp:26