13 template <
typename BUFFER>
14 consteval auto deduce_buffer_element_type()
noexcept
16 if constexpr (
requires {
typename BUFFER::value_type; })
17 return std::type_identity<typename BUFFER::value_type>{};
18 else if constexpr (
requires {
typename BUFFER::char_type; })
19 return std::type_identity<typename BUFFER::char_type>{};
30 template <
typename BUFFER>
34 template <
typename BUFFER,
typename T>
37 if constexpr (
requires {
buffer.append(
val); })
42 else if constexpr (
requires {
buffer.push_back(
val); })
52 else if constexpr (
requires {
buffer.put(
val); })
59 static_assert(!std::same_as<T, T>,
"buffer cannot be appended with this value type - buffer_append might need to be specialized");
65 template <
typename BUFFER,
typename ELEMENT_VALUE>
71 template <
typename BUFFER>
84 template <
typename BUFFER,
typename RANGE>
88 if constexpr (std::ranges::sized_range<RANGE>)
109 if constexpr (
requires {
buffer.append(std::to_address(std::ranges::begin(
range)), std::ranges::size(
range)); } && std::ranges::sized_range<RANGE>)
111 const auto size = std::ranges::size(
range);
112 buffer.append(std::to_address(std::ranges::begin(
range)), size);
115 else if constexpr (
requires {
buffer.write(std::to_address(std::ranges::begin(
range)), std::ranges::size(
range)); } && std::ranges::sized_range<RANGE>)
117 const auto size = std::ranges::size(
range);
119 buffer.write(std::to_address(std::ranges::begin(
range)), size);
127 for (
auto&& value : std::forward<RANGE>(
range))
138 template <
typename BUFFER,
typename CHAR_TYPE>
146 template <
typename BUFFER,
typename CHAR_TYPE>
154 template <
typename BUFFER,
size_t N,
typename CHAR_TYPE>
162 template <
typename BUFFER,
typename ELEMENT_TYPE = buffer_element_type<BUFFER>>
171 else if (cp < 0x800) {
175 else if (cp < 0x10000) {
191 template <
typename BUFFER,
typename STRING_TYPE,
typename ELEMENT_TYPE = buffer_element_type<BUFFER>>
204 template <
typename BUFFER,
typename POD>
212 template <
typename BUFFER,
typename CALLBACK>
213 requires std::invocable<CALLBACK, size_t, std::string_view, BUFFER&>
220 auto text = consume_until(
fmt,
'{');
224 std::ignore = consume(
fmt,
'{');
226 if (consume(
fmt,
'{'))
236 throw std::format_error(
"missing '}' in format string");
241 aid = string_ops::stoull(
num);
Checks if an element value is appendable to a buffer.
constexpr auto bit_count
Equal to the number of bits in the type.
size_t buffer_append_cstring(BUFFER &buffer, const CHAR_TYPE(&cstr)[N])
Appends characters in the cstr literal array to the buffer
typename decltype(detail::deduce_buffer_element_type< BUFFER >())::type buffer_element_type
void callback_format_to(BUFFER &buffer, std::string_view fmt, CALLBACK &&callback)
TODO: Make this work - currently needs string_ops
bool buffer_append(BUFFER &&buffer, T &&val)
Primary function to append a value (preferably the buffer element type) to the buffer.
size_t buffer_append_pod(BUFFER &buffer, POD const &pod)
Appends a POD values internal object representation to a buffer.
size_t buffer_append_cstring_ptr(BUFFER &buffer, const CHAR_TYPE *cstr)
Appends characters in the cstr to the buffer
bool buffer_reserve(BUFFER &buffer, size_t additional)
Reserves additional elements in the buffer, if possible.
size_t buffer_append_range(BUFFER &buffer, RANGE &&range)
Appends elements in the range to the buffer
size_t buffer_append_utf8(BUFFER &buffer, char32_t cp)
Appends UTF-8 codeunits that represent the Unicode code-point cp to the buffer. Assumes the codepoint...
std::string_view consume_until(std::string_view &str, FUNC &&pred)
Consumes characters from the beginning of str until one matches pred(str[0]), exclusive.
std::string_view consume_until_delim(std::string_view &str, char c)
Consumes characters from the beginning of str until one is equal to c, inclusive.
bool consume_at_end(std::string_view &str, char val)
Consumes the last character from str if it matches val.
The below code is based on Sun's libm library code, which is licensed under the following license:
Primary namespace for everything in this library.
std::span< TO > as_bytelikes(std::span< FROM, N > bytes) noexcept
Converts a span of trivial values to a span of bytelike s.