microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
Public Member Functions | List of all members
microfmt::c_string_span_sink Class Reference

Output sink that guarantees a null-terminated string within an externally provided, fixed-size memory buffer. More...

#include <c_string_span_sink.hpp>

Inheritance diagram for microfmt::c_string_span_sink:
Inheritance graph
[legend]
Collaboration diagram for microfmt::c_string_span_sink:
Collaboration graph
[legend]

Public Member Functions

constexpr c_string_span_sink (span< char > buf RELOCO_LIFETIMEBOUND RELOCO_LIFETIME_CAPTURE_BY_THIS) noexcept
 Constructs a null-terminated string sink over a microfmt::span.
 
sink as_sink () noexcept RELOCO_LIFETIMEBOUND
 Creates a type-erased sink adapter pointing to this instance.
 
constexpr const char * c_str () const noexcept RELOCO_LIFETIMEBOUND
 Returns a null-terminated C string pointer.
 
constexpr microfmt::string_view view () const noexcept RELOCO_LIFETIMEBOUND
 Returns a string view over the characters written (excluding null terminator).
 
constexpr std::size_t size () const noexcept
 Returns the length of the string in bytes (excluding null terminator).
 
constexpr std::size_t max_size () const noexcept
 Returns the maximum characters the sink can store (excluding null terminator).
 
RELOCO_REINITIALIZES constexpr void reset () noexcept
 Resets the sink to an empty, null-terminated state.
 

Detailed Description

Output sink that guarantees a null-terminated string within an externally provided, fixed-size memory buffer.

Reserves 1 byte for the trailing \0. Output is clamped to the buffer's capacity minus 1, and is guaranteed to be null-terminated after every write.

Constructor & Destructor Documentation

◆ c_string_span_sink()

constexpr microfmt::c_string_span_sink::c_string_span_sink ( span< char > buf RELOCO_LIFETIMEBOUND  RELOCO_LIFETIME_CAPTURE_BY_THIS)
inlineexplicitconstexprnoexcept

Constructs a null-terminated string sink over a microfmt::span.

Parameters
bufThe target character buffer view. If empty, the sink discards all writes safely.

Member Function Documentation

◆ as_sink()

sink microfmt::c_string_span_sink::as_sink ( )
inlinenoexcept

Creates a type-erased sink adapter pointing to this instance.

Returns
A lightweight sink struct configured to append and null-terminate.

◆ c_str()

constexpr const char * microfmt::c_string_span_sink::c_str ( ) const
inlineconstexprnoexcept

Returns a null-terminated C string pointer.

Returns
Pointer to the underlying null-terminated buffer, or a safe empty static string if the initial span was empty.

◆ max_size()

constexpr std::size_t microfmt::c_string_span_sink::max_size ( ) const
inlineconstexprnoexcept

Returns the maximum characters the sink can store (excluding null terminator).

Returns
Maximum payload capacity (buf.size() - 1).

◆ reset()

RELOCO_REINITIALIZES constexpr void microfmt::c_string_span_sink::reset ( )
inlineconstexprnoexcept

Resets the sink to an empty, null-terminated state.

◆ size()

constexpr std::size_t microfmt::c_string_span_sink::size ( ) const
inlineconstexprnoexcept

Returns the length of the string in bytes (excluding null terminator).

Returns
String length in bytes.

◆ view()

constexpr microfmt::string_view microfmt::c_string_span_sink::view ( ) const
inlineconstexprnoexcept

Returns a string view over the characters written (excluding null terminator).

Returns
Non-owning view of formatted text.

The documentation for this class was generated from the following file: