27 static constexpr auto npos = std::string_view::npos;
30 : dat(nullptr), siz(0) {}
32 : dat(s), siz(
std::char_traits<char>::length(s)) {}
34 : dat(s), siz(n) { assert(s[n] ==
'\0'); }
38 [[nodiscard]]
constexpr auto begin()
const {
return dat; }
39 [[nodiscard]]
constexpr auto end()
const {
return dat + siz; }
41 [[nodiscard]]
constexpr auto size()
const {
return siz; }
42 [[nodiscard]]
constexpr auto empty()
const {
return siz == 0; }
48 [[nodiscard]]
constexpr char front()
const {
return *dat; }
49 [[nodiscard]]
constexpr char back()
const {
return *(dat + siz - 1); }
50 [[nodiscard]]
constexpr const char*
data()
const {
return dat; }
51 [[nodiscard]]
constexpr const char*
c_str()
const {
return dat; }
54 return view().find(c, pos);
59 return {dat + pos, siz - pos};
63 return view().substr(pos, count);
66 [[nodiscard]]
constexpr bool starts_with(std::string_view sv)
const {
67 return view().starts_with(sv);
70 return view().starts_with(c);
72 [[nodiscard]]
constexpr bool starts_with(
const char* s)
const {
73 return view().starts_with(s);
75 [[nodiscard]]
constexpr bool ends_with(std::string_view sv)
const {
76 return view().ends_with(sv);
78 [[nodiscard]]
constexpr bool ends_with(
char c)
const {
79 return view().ends_with(c);
81 [[nodiscard]]
constexpr bool ends_with(
const char* s)
const {
82 return view().ends_with(s);
85 [[nodiscard]]
explicit operator std::string()
const {
88 [[nodiscard]]
constexpr std::string_view
view()
const {
91 [[nodiscard]]
constexpr operator std::string_view()
const {
100static_assert(std::is_trivially_destructible_v<zstring_view>);
101static_assert(std::is_trivially_copyable_v<zstring_view>);
102static_assert(std::is_trivially_copy_constructible_v<zstring_view>);
103static_assert(std::is_trivially_move_constructible_v<zstring_view>);
104static_assert(std::is_trivially_assignable_v<zstring_view, zstring_view>);
105static_assert(std::is_trivially_copy_assignable_v<zstring_view>);
106static_assert(std::is_trivially_move_assignable_v<zstring_view>);
112 return std::string_view(x) == std::string_view(y);
115 return std::string_view(x) == std::string_view(y);
118 return std::string_view(x) == y;
121 return std::string_view(x) == std::string_view(y);
127 return std::string_view(x) < std::string_view(y);
130 return std::string_view(x) < std::string_view(y);
133 return std::string_view(x) < y;
136 return std::string_view(x) < std::string_view(y);
139 return std::string_view(x) <= std::string_view(y);
142 return std::string_view(x) <= std::string_view(y);
145 return std::string_view(x) <= y;
148 return std::string_view(x) <= std::string_view(y);
151 return std::string_view(x) > std::string_view(y);
154 return std::string_view(x) > std::string_view(y);
157 return std::string_view(x) > y;
160 return std::string_view(x) > std::string_view(y);
163 return std::string_view(x) >= std::string_view(y);
166 return std::string_view(x) >= std::string_view(y);
169 return std::string_view(x) >= y;
172 return std::string_view(x) >= std::string_view(y);
177 os << std::string_view(str);
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
constexpr bool ends_with(char c) const
constexpr zstring_view(const char *s)
constexpr bool starts_with(char c) const
constexpr auto begin() const
constexpr bool starts_with(const char *s) const
constexpr auto size() const
constexpr char back() const
zstring_view(const std::string &s)
constexpr std::string_view substr(size_type pos, size_type count) const
constexpr zstring_view(const char *s, size_t n)
constexpr const char * data() const
constexpr char operator[](size_type i) const
const char * const_iterator
constexpr bool ends_with(std::string_view sv) const
constexpr auto end() const
constexpr bool ends_with(const char *s) const
static constexpr auto npos
constexpr const char * c_str() const
constexpr char front() const
constexpr auto find(char c, size_type pos=0) const
constexpr zstring_view substr(size_type pos) const
constexpr bool starts_with(std::string_view sv) const
constexpr auto empty() const
constexpr std::string_view view() const
constexpr bool operator==(const zstring_view &x, const zstring_view &y)
constexpr auto operator<(const zstring_view &x, const zstring_view &y)
constexpr auto operator>(const zstring_view &x, const zstring_view &y)
std::ostream & operator<<(std::ostream &os, const zstring_view &str)
constexpr auto operator<=(const zstring_view &x, const zstring_view &y)
constexpr auto operator>=(const zstring_view &x, const zstring_view &y)
constexpr auto begin(const zstring_view &x)
constexpr auto end(const zstring_view &x)