1#ifndef TEMPORARYSTRING_HH
2#define TEMPORARYSTRING_HH
38 : n(
std::char_traits<char>::length(s)), ptr(s) {}
63 [[nodiscard]]
auto size()
const {
return n; }
64 [[nodiscard]]
auto empty()
const {
return n == 0; }
66 [[nodiscard]]
const char*
data()
const {
return ptr; }
67 [[nodiscard]]
const char*
c_str()
const {
return ptr; }
69 [[nodiscard]] std::string_view
view()
const {
return {ptr, n}; }
70 [[nodiscard]]
operator std::string_view()
const {
return {ptr, n}; }
73 [[nodiscard]]
bool starts_with(std::string_view s)
const {
return view().starts_with(s); }
75 [[nodiscard]]
bool starts_with(
const char* s)
const {
return view().starts_with(s); }
76 [[nodiscard]]
bool ends_with(std::string_view s)
const {
return view().ends_with(s); }
77 [[nodiscard]]
bool ends_with(
char c)
const {
return view().ends_with(c); }
78 [[nodiscard]]
bool ends_with(
const char* s)
const {
return view().ends_with(s); }
84 std::array<char, BUFSIZE + 1> buffer;
89 os << std::string_view(str);
std::unique_ptr< char, FreeStringStorage > StringStorage
StringStorage allocate_string_storage(size_t size)
Allocate a 'StringStorage' large enough for 'size' characters.
std::ostream & operator<<(std::ostream &os, const TemporaryString &str)
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
TemporaryString(TemporaryString &&)=delete
TemporaryString(zstring_view s)
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
bool ends_with(char c) const
TemporaryString & operator=(const TemporaryString &)=delete
TemporaryString(const char *s)
TemporaryString(size_t n_, std::invocable< char * > auto fillOp)
~TemporaryString()=default
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.