|
| | FixedString () noexcept=default |
| | Construct an empty string.
|
| |
| | FixedString (const char *s) noexcept |
| | Construct from a NUL-terminated C string (clamped to N, see assign).
|
| |
| | FixedString (std::string_view sv) noexcept |
| | Construct from a string view (clamped to N, see assign).
|
| |
| | FixedString (const std::string &s) noexcept |
| | Construct from a std::string (the easy on-ramp; truncated to N).
|
| |
| FixedString & | operator= (const char *s) noexcept |
| | Assign from a NUL-terminated C string (clamped to N, see assign).
|
| |
| FixedString & | operator= (std::string_view sv) noexcept |
| | Assign from a string view (clamped to N, see assign).
|
| |
| FixedString & | operator= (const std::string &s) noexcept |
| | Assign from a std::string (clamped to N, see assign).
|
| |
| FixedString & | assign (std::string_view sv) noexcept |
| | Replace the contents with sv, clamped to N bytes.
|
| |
| void | set_len (std::size_t n) noexcept |
| | Decode hook: set the logical length and (re)place the trailing NUL.
|
| |
| char * | data () noexcept |
| | Mutable pointer to the character buffer (decode target).
|
| |
| const char * | data () const noexcept |
| | Const pointer to the character buffer.
|
| |
| const char * | c_str () const noexcept |
| | NUL-terminated view of the contents.
|
| |
| std::size_t | size () const noexcept |
| | Number of characters currently stored.
|
| |
| std::size_t | length () const noexcept |
| | Alias of size.
|
| |
| bool | empty () const noexcept |
| | True if the string is empty.
|
| |
| char & | operator[] (std::size_t i) noexcept |
| | Access the character at i (no bounds checking).
|
| |
| const char & | operator[] (std::size_t i) const noexcept |
| | Access the character at i (no bounds checking).
|
| |
| char * | begin () noexcept |
| | Iterator to the first character.
|
| |
| char * | end () noexcept |
| | Iterator past the last character.
|
| |
| const char * | begin () const noexcept |
| | Const iterator to the first character.
|
| |
| const char * | end () const noexcept |
| | Const iterator past the last character.
|
| |
| void | clear () noexcept |
| | Reset to an empty string.
|
| |
| std::string_view | view () const noexcept |
| | Non-owning view over the current characters.
|
| |
| | operator std::string_view () const noexcept |
| | Implicit conversion to std::string_view.
|
| |
| std::string | str () const |
| | Copy the contents into an owning std::string (allocates).
|
| |
| bool | operator== (std::string_view rhs) const noexcept |
| | Equality against any string view-like operand.
|
| |
| bool | operator!= (std::string_view rhs) const noexcept |
| | Inequality against any string view-like operand.
|
| |
template<std::size_t N>
class sofab::FixedString< N >
Fixed-capacity, heap-free string of up to N characters.
A drop-in, embedded-friendly stand-in for std::string on both the encode and decode paths. The characters live in an inline std::array, so an instance allocates nothing, never throws (an over-long value is clamped to N bytes at a UTF-8 character boundary, see assign), and compiles cleanly under -fno-exceptions / -fno-rtti. The buffer never moves, so an instance stays a valid decode destination across every IStreamImpl::feed chunk.
The storage is N+1 bytes: one extra slot always holds a trailing NUL so c_str and the std::string_view encode path remain valid even at full length N. The buffer is zero-initialised, so the NUL is present from construction and is re-placed by every length-changing operation.
- Generator integration contract
- Generated code is spelled exactly as for
std::string, so this type only has to keep the surface the typed calls look for:
- decode emits
is.readString(s, maxlen); โ IStreamImpl::readString picks the heap-free branch off set_len / capacity, rejects an over-N payload as INVALID (ยง7.1) rather than truncating it, and fills data before fixing size;
- encode emits
os.write(id, s); โ the implicit operator std::string_view routes it through the existing string encode branch, byte-for-byte identical to the same-content std::string.
- Template Parameters
-
| N | Maximum number of characters (excluding the reserved NUL slot). |
Definition at line 799 of file sofab.hpp.
Replace the contents with sv, clamped to N bytes.
The assignment-time clamp is a documented contract of the static storage (the generator's allow_dynamic: false): a value longer than N is cut, not refused, before any encoder sees it. The cut never lands inside a UTF-8 character – it moves back to the start of the character that would not fit whole, so the kept prefix is valid UTF-8 whenever sv is.
- Parameters
-
| sv | Source characters (may contain embedded NULs). |
- Returns
- Reference to
*this.
Definition at line 874 of file sofab.hpp.