1#ifndef TEMPORARYSTRING_HH
2#define TEMPORARYSTRING_HH
39 : n(
std::char_traits<char>::length(s)), ptr(s) {}
64 [[nodiscard]]
auto size()
const {
return n; }
65 [[nodiscard]]
auto empty()
const {
return n == 0; }
67 [[nodiscard]]
const char*
data()
const {
return ptr; }
68 [[nodiscard]]
const char*
c_str()
const {
return ptr; }
70 [[nodiscard]] std::string_view
view()
const {
return {ptr, n}; }
71 [[nodiscard]]
operator std::string_view()
const {
return {ptr, n}; }
74 [[nodiscard]]
bool starts_with(std::string_view s)
const {
return view().starts_with(s); }
76 [[nodiscard]]
bool starts_with(
const char* s)
const {
return view().starts_with(s); }
77 [[nodiscard]]
bool ends_with(std::string_view s)
const {
return view().ends_with(s); }
78 [[nodiscard]]
bool ends_with(
char c)
const {
return view().ends_with(c); }
79 [[nodiscard]]
bool ends_with(
const char* s)
const {
return view().ends_with(s); }
82 return std::string_view(x) == std::string_view(y);
85 return std::string_view(x) == std::string_view(y);
88 return std::string_view(x) == std::string_view(y);
91 return std::string_view(x) == y;
94 return std::string_view(x) == std::string_view(y);
99 os << std::string_view(str);
107 std::array<char, BUFSIZE + 1> buffer;
std::unique_ptr< char, FreeStringStorage > StringStorage
StringStorage allocate_string_storage(size_t size)
Allocate a 'StringStorage' large enough for 'size' characters.
static constexpr size_t BUFSIZE
TemporaryString & operator=(TemporaryString &&)=delete
const char * c_str() const
bool starts_with(char c) const
bool starts_with(const char *s) const
std::string_view view() const
friend bool operator==(const TemporaryString &x, const zstring_view &y)
TemporaryString(TemporaryString &&)=delete
TemporaryString(zstring_view s)
friend bool operator==(const TemporaryString &x, const TemporaryString &y)
bool ends_with(std::string_view s) const
const char * data() const
bool starts_with(std::string_view s) const
bool ends_with(const char *s) const
TemporaryString(const TemporaryString &)=delete
friend bool operator==(const TemporaryString &x, const std::string_view &y)
friend bool operator==(const TemporaryString &x, const std::string &y)
bool ends_with(char c) const
TemporaryString & operator=(const TemporaryString &)=delete
friend bool operator==(const TemporaryString &x, const char *y)
TemporaryString(const char *s)
TemporaryString(size_t n_, std::invocable< char * > auto fillOp)
~TemporaryString()=default
friend std::ostream & operator<<(std::ostream &os, const TemporaryString &str)
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.