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);
56 [[nodiscard]]
constexpr auto find(
const char* s,
size_type pos = 0)
const {
57 return view().find(s, pos);
62 return {dat + pos, siz - pos};
66 return view().substr(pos, count);
69 [[nodiscard]]
constexpr bool starts_with(std::string_view sv)
const {
70 return view().starts_with(sv);
73 return view().starts_with(c);
75 [[nodiscard]]
constexpr bool starts_with(
const char* s)
const {
76 return view().starts_with(s);
78 [[nodiscard]]
constexpr bool ends_with(std::string_view sv)
const {
79 return view().ends_with(sv);
81 [[nodiscard]]
constexpr bool ends_with(
char c)
const {
82 return view().ends_with(c);
84 [[nodiscard]]
constexpr bool ends_with(
const char* s)
const {
85 return view().ends_with(s);
88 [[nodiscard]]
explicit operator std::string()
const {
91 [[nodiscard]]
constexpr std::string_view
view()
const {
94 [[nodiscard]]
explicit(
false)
constexpr operator std::string_view()
const {
99 return std::string_view(x) == std::string_view(y);
102 return std::string_view(x) == std::string_view(y);
105 return std::string_view(x) == y;
108 return std::string_view(x) == std::string_view(y);
113 os << std::string_view(str);
122static_assert(std::is_trivially_destructible_v<zstring_view>);
123static_assert(std::is_trivially_copyable_v<zstring_view>);
124static_assert(std::is_trivially_copy_constructible_v<zstring_view>);
125static_assert(std::is_trivially_move_constructible_v<zstring_view>);
126static_assert(std::is_trivially_assignable_v<zstring_view, zstring_view>);
127static_assert(std::is_trivially_copy_assignable_v<zstring_view>);
128static_assert(std::is_trivially_move_assignable_v<zstring_view>);
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) < y;
145 return std::string_view(x) < std::string_view(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) <= y;
157 return std::string_view(x) <= std::string_view(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) > y;
169 return std::string_view(x) > std::string_view(y);
172 return std::string_view(x) >= std::string_view(y);
175 return std::string_view(x) >= std::string_view(y);
178 return std::string_view(x) >= y;
181 return std::string_view(x) >= std::string_view(y);
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 auto find(const char *s, size_type pos=0) const
constexpr char back() const
zstring_view(const std::string &s)
friend std::ostream & operator<<(std::ostream &os, const zstring_view &str)
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
constexpr friend bool operator==(const zstring_view &x, const char *y)
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
friend bool operator==(const zstring_view &x, const std::string &y)
constexpr std::string_view view() const
constexpr friend bool operator==(const zstring_view &x, const std::string_view &y)
constexpr auto 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)
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)