27 #include <string_view>
29 #ifdef EMLABCPP_USE_NLOHMANN_JSON
30 #include <nlohmann/json.hpp>
36 template < std::
size_t N >
44 std::fill_n( this->
data(),
N,
'\0' );
50 std::copy_n(
sv.begin(),
std::min(
sv.size(),
N - 1 ), this->begin() );
53 template < std::
size_t M >
57 static_assert( M <
N );
58 std::copy_n( msg, M, this->
begin() );
61 template < std::
size_t M >
65 static_assert( M <
N );
66 std::copy_n( msg.
data(), M, this->begin() );
69 operator std::string_view()
const
74 std::string_view
sv()
const
76 return std::string_view( this->
data(),
size() );
94 constexpr
auto end()
const
104 constexpr
char const*
data()
const
109 [[nodiscard]] constexpr std::size_t
size()
const
111 for ( std::size_t i = 0; i <
N; i++ )
112 if ( data_[i] ==
'\0' )
117 template < std::
size_t M >
120 return std::string_view{ *
this } <=> std::string_view{ other };
123 template < std::
size_t M >
126 return std::string_view{ *
this } == std::string_view{ other };
129 constexpr
bool operator==( std::string_view other )
const noexcept
131 return std::string_view{ *
this } == other;
136 std::size_t curr_size =
size();
140 this->begin() + curr_size );
145 std::array< char, N > data_;
150 template <
typename T >
153 static constexpr
bool value =
false;
156 template < std::
size_t N >
164 template <
typename T >
167 template < std::
size_t N >
170 return os << std::string_view( sb );
173 #ifdef EMLABCPP_USE_NLOHMANN_JSON
175 template < std::
size_t N >
176 void to_json( nlohmann::json& j, string_buffer< N >
const& buffer )
178 j = std::string_view{ buffer };
181 template < std::
size_t N >
182 void from_json( nlohmann::json
const& j, string_buffer< N >& buffer )
184 std::string
const s = j;
185 buffer = string_buffer< N >( std::string_view{ s } );
MIT License.
Definition: impl.h:31
concept is_string_buffer_v
Definition: string_buffer.h:165
constexpr Derived const & min(vec_point_base< Derived, N > const &a, vec_point_base< Derived, N > const &b)
Definition: vec_point_base.h:236
std::ostream & operator<<(std::ostream &os, string_buffer< N > const &sb)
Definition: string_buffer.h:168
N
Definition: static_storage.h:97
Definition: string_buffer.h:152
static constexpr bool value
Definition: string_buffer.h:153
Definition: string_buffer.h:38
constexpr string_buffer(std::string_view sv)
Definition: string_buffer.h:47
constexpr bool operator==(string_buffer< M > const &other) const noexcept
Definition: string_buffer.h:124
std::string_view sv() const
Definition: string_buffer.h:74
constexpr auto end() const
Definition: string_buffer.h:94
constexpr auto begin() const
Definition: string_buffer.h:84
std::array< char, N > base_type
Definition: string_buffer.h:40
constexpr bool operator==(std::string_view other) const noexcept
Definition: string_buffer.h:129
constexpr char * data()
Definition: string_buffer.h:99
constexpr auto end()
Definition: string_buffer.h:89
constexpr string_buffer(char const (&msg)[M])
Definition: string_buffer.h:54
string_buffer & extend(std::string_view sv)
Definition: string_buffer.h:134
constexpr char const * data() const
Definition: string_buffer.h:104
constexpr auto begin()
Definition: string_buffer.h:79
constexpr std::size_t size() const
Definition: string_buffer.h:109
constexpr string_buffer()
Definition: string_buffer.h:42
constexpr auto operator<=>(string_buffer< M > const &other) const noexcept
Definition: string_buffer.h:118
constexpr string_buffer(string_buffer< M > const &msg)
Definition: string_buffer.h:62
static constexpr std::size_t capacity
Definition: string_buffer.h:39