nfx-stringbuilder 0.7.0
Cross-platform C++20 library for zero-allocation string building with Small Buffer Optimization
Loading...
Searching...
No Matches
nfx::string::StringBuilder Class Referencefinal

High-performance string builder with efficient memory management. More...

#include <nfx/string/StringBuilder.h>

Public Types

using value_type = char
 Character type for iterator compatibility.
using Iterator = char*
 Mutable iterator type for buffer traversal.
using ConstIterator = const char*
 Immutable iterator type for buffer traversal.
using iterator = Iterator
 Type alias for iterator.
using const_iterator = ConstIterator
 Type alias for const iterator.

Public Member Functions

 StringBuilder ()
 Default constructor.
 StringBuilder (size_t initialCapacity)
 Constructor with specified initial capacity.
 StringBuilder (const StringBuilder &other)
 Copy constructor.
 StringBuilder (StringBuilder &&other) noexcept
 Move constructor.
 ~StringBuilder ()=default
 Destructor.
StringBuilderoperator= (const StringBuilder &other)
 Copy assignment operator.
StringBuilderoperator= (StringBuilder &&other) noexcept
 Move assignment operator.
size_t size () const noexcept
 Get current buffer size in bytes.
size_t capacity () const noexcept
 Get current buffer capacity in bytes.
bool isEmpty () const noexcept
 Check if buffer is empty.
char * data () noexcept
 Get mutable pointer to buffer data.
const char * data () const noexcept
 Get immutable pointer to buffer data.
char & operator[] (size_t index)
 Access buffer element by index (mutable).
const char & operator[] (size_t index) const
 Access buffer element by index (immutable).
void clear () noexcept
 Clear buffer content without deallocating memory.
void reserve (size_t newCapacity)
 Reserve minimum capacity for buffer.
void resize (size_t newSize)
 Resize buffer to specified size.
StringBuilderappend (std::string_view str)
 Appends string_view contents to the buffer efficiently.
StringBuilderappend (const std::string &str)
 Appends std::string contents to the buffer.
StringBuilderappend (const char *str)
 Appends null-terminated C-string to the buffer.
template<size_t N>
NFX_STRINGBUILDER_FORCE_INLINE StringBuilderappend (const char(&str)[N])
 Appends string literal with compile-time length (zero strlen overhead).
StringBuilderappend (char c)
 Appends single character to the buffer.
StringBuilderappend (std::int8_t value)
 Appends 8-bit signed integer to the buffer.
StringBuilderappend (std::uint8_t value)
 Appends 8-bit unsigned integer to the buffer.
StringBuilderappend (std::int16_t value)
 Appends 16-bit signed integer to the buffer.
StringBuilderappend (std::uint16_t value)
 Appends 16-bit unsigned integer to the buffer.
StringBuilderappend (std::int32_t value)
 Appends 32-bit signed integer to the buffer.
StringBuilderappend (std::uint32_t value)
 Appends 32-bit unsigned integer to the buffer.
StringBuilderappend (std::int64_t value)
 Appends 64-bit signed integer to the buffer.
StringBuilderappend (std::uint64_t value)
 Appends 64-bit unsigned integer to the buffer.
StringBuilderappend (float value)
 Appends single-precision floating-point to the buffer.
StringBuilderappend (double value)
 Appends double-precision floating-point to the buffer.
StringBuilderappendLine (std::string_view str="")
 Appends string_view contents followed by a newline character.
StringBuilderappendLine (const std::string &str)
 Appends std::string contents followed by a newline character.
StringBuilderappendLine (const char *str)
 Appends null-terminated C-string followed by a newline character.
StringBuilderprepend (std::string_view str)
 Prepends string_view contents to the buffer.
StringBuilderprepend (const std::string &str)
 Prepends std::string contents to the buffer.
StringBuilderprepend (const char *str)
 Prepends null-terminated C-string to the buffer.
StringBuilderprepend (char c)
 Prepends single character to the buffer.
StringBuilderprepend (std::int8_t value)
 Prepends 8-bit signed integer to the buffer.
StringBuilderprepend (std::uint8_t value)
 Prepends 8-bit unsigned integer to the buffer.
StringBuilderprepend (std::int16_t value)
 Prepends 16-bit signed integer to the buffer.
StringBuilderprepend (std::uint16_t value)
 Prepends 16-bit unsigned integer to the buffer.
StringBuilderprepend (std::int32_t value)
 Prepends 32-bit signed integer to the buffer.
StringBuilderprepend (std::uint32_t value)
 Prepends 32-bit unsigned integer to the buffer.
StringBuilderprepend (std::int64_t value)
 Prepends 64-bit signed integer to the buffer.
StringBuilderprepend (std::uint64_t value)
 Prepends 64-bit unsigned integer to the buffer.
StringBuilderprepend (float value)
 Prepends single-precision floating-point to the buffer.
StringBuilderprepend (double value)
 Prepends double-precision floating-point to the buffer.
template<typename T, typename... Args, typename = std::enable_if_t<( sizeof...( Args ) > 0 )>>
StringBuilderappend (T &&first, Args &&... args)
 Append multiple arguments in one call (strings, characters, numeric types).
template<typename Container>
StringBuilderjoin (const Container &items, std::string_view delimiter)
 Join container elements with delimiter.
template<typename Container>
StringBuilderjoin (const Container &items, char delimiter)
 Join container elements with character delimiter.
StringBuilderoperator<< (std::string_view str)
 Stream operator for string_view.
StringBuilderoperator<< (const std::string &str)
 Stream operator for std::string.
StringBuilderoperator<< (const char *str)
 Stream operator for C-string.
template<size_t N>
NFX_STRINGBUILDER_FORCE_INLINE StringBuilderoperator<< (const char(&str)[N])
 Stream operator for string literal (zero strlen overhead).
StringBuilderoperator<< (char c)
 Stream operator for single character.
StringBuilderoperator<< (std::int8_t value)
 Stream operator for 8-bit signed integer.
StringBuilderoperator<< (std::uint8_t value)
 Stream operator for 8-bit unsigned integer.
StringBuilderoperator<< (std::int16_t value)
 Stream operator for 16-bit signed integer.
StringBuilderoperator<< (std::uint16_t value)
 Stream operator for 16-bit unsigned integer.
StringBuilderoperator<< (std::int32_t value)
 Stream operator for 32-bit signed integer.
StringBuilderoperator<< (std::uint32_t value)
 Stream operator for 32-bit unsigned integer.
StringBuilderoperator<< (std::int64_t value)
 Stream operator for 64-bit signed integer.
StringBuilderoperator<< (std::uint64_t value)
 Stream operator for 64-bit unsigned integer.
StringBuilderoperator<< (float value)
 Stream operator for single-precision floating-point.
StringBuilderoperator<< (double value)
 Stream operator for double-precision floating-point.
template<typename... Args>
StringBuilderformat (std::format_string< Args... > fmt, Args &&... args)
 Format and append text using std::format.
std::string toString () const &
 Convert buffer content to std::string.
std::string toString () &&
 Convert buffer to string by moving (rvalue-qualified).
std::string_view toStringView () const noexcept
 Get string_view of buffer content.
void push_back (char c)
 Appends single character to the buffer (for STL compatibility).
Iterator begin () noexcept
 Get mutable iterator to beginning of buffer.
ConstIterator begin () const noexcept
 Get immutable iterator to beginning of buffer.
Iterator end () noexcept
 Get mutable iterator to end of buffer.
ConstIterator end () const noexcept
 Get immutable iterator to end of buffer.

Detailed Description

High-performance string builder with efficient memory management.

Provides a growable character buffer optimized for string building operations. Features automatic capacity management, Small Buffer Optimization (SBO), iterator support, and zero-copy string_view access.

Warning
Not thread-safe - external synchronization required for concurrent access. Each StringBuilder instance should be used by a single thread or protected by external synchronization mechanisms.

Definition at line 107 of file StringBuilder.h.

Member Typedef Documentation

◆ const_iterator

Type alias for const iterator.

Definition at line 748 of file StringBuilder.h.

◆ ConstIterator

Immutable iterator type for buffer traversal.

Definition at line 742 of file StringBuilder.h.

◆ Iterator

Mutable iterator type for buffer traversal.

Definition at line 739 of file StringBuilder.h.

◆ iterator

Type alias for iterator.

Definition at line 745 of file StringBuilder.h.

◆ value_type

Character type for iterator compatibility.

Definition at line 736 of file StringBuilder.h.

Constructor & Destructor Documentation

◆ StringBuilder() [1/3]

nfx::string::StringBuilder::StringBuilder ( size_t initialCapacity)
explicit

Constructor with specified initial capacity.

Parameters
initialCapacityInitial buffer capacity in bytes

Pre-allocates buffer to avoid reallocations during initial growth

◆ StringBuilder() [2/3]

nfx::string::StringBuilder::StringBuilder ( const StringBuilder & other)

Copy constructor.

Parameters
otherThe StringBuilder to copy from

◆ StringBuilder() [3/3]

nfx::string::StringBuilder::StringBuilder ( StringBuilder && other)
noexcept

Move constructor.

Parameters
otherThe StringBuilder to move from

Member Function Documentation

◆ append() [1/16]

StringBuilder & nfx::string::StringBuilder::append ( char c)
inline

Appends single character to the buffer.

Parameters
cCharacter to append
Returns
Reference to this StringBuilder for chaining

◆ append() [2/16]

StringBuilder & nfx::string::StringBuilder::append ( const char * str)
inline

Appends null-terminated C-string to the buffer.

Parameters
strNull-terminated C-string to append (null pointer handled gracefully)
Returns
Reference to this StringBuilder for chaining

◆ append() [3/16]

template<size_t N>
NFX_STRINGBUILDER_FORCE_INLINE StringBuilder & nfx::string::StringBuilder::append ( const char(&) str[N])

Appends string literal with compile-time length (zero strlen overhead).

Template Parameters
NString literal length (deduced by compiler)
Parameters
strString literal
Returns
Reference to this StringBuilder for chaining

◆ append() [4/16]

StringBuilder & nfx::string::StringBuilder::append ( const std::string & str)
inline

Appends std::string contents to the buffer.

Parameters
strString to append
Returns
Reference to this StringBuilder for chaining

◆ append() [5/16]

StringBuilder & nfx::string::StringBuilder::append ( double value)
inline

Appends double-precision floating-point to the buffer.

Parameters
valueFloating-point value to append
Returns
Reference to this StringBuilder for chaining

◆ append() [6/16]

StringBuilder & nfx::string::StringBuilder::append ( float value)
inline

Appends single-precision floating-point to the buffer.

Parameters
valueFloating-point value to append
Returns
Reference to this StringBuilder for chaining

◆ append() [7/16]

StringBuilder & nfx::string::StringBuilder::append ( std::int16_t value)
inline

Appends 16-bit signed integer to the buffer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ append() [8/16]

StringBuilder & nfx::string::StringBuilder::append ( std::int32_t value)
inline

Appends 32-bit signed integer to the buffer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ append() [9/16]

StringBuilder & nfx::string::StringBuilder::append ( std::int64_t value)
inline

Appends 64-bit signed integer to the buffer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ append() [10/16]

StringBuilder & nfx::string::StringBuilder::append ( std::int8_t value)
inline

Appends 8-bit signed integer to the buffer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ append() [11/16]

StringBuilder & nfx::string::StringBuilder::append ( std::string_view str)
inline

Appends string_view contents to the buffer efficiently.

Parameters
strString view to append
Returns
Reference to this StringBuilder for chaining

◆ append() [12/16]

StringBuilder & nfx::string::StringBuilder::append ( std::uint16_t value)
inline

Appends 16-bit unsigned integer to the buffer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ append() [13/16]

StringBuilder & nfx::string::StringBuilder::append ( std::uint32_t value)
inline

Appends 32-bit unsigned integer to the buffer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ append() [14/16]

StringBuilder & nfx::string::StringBuilder::append ( std::uint64_t value)
inline

Appends 64-bit unsigned integer to the buffer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ append() [15/16]

StringBuilder & nfx::string::StringBuilder::append ( std::uint8_t value)
inline

Appends 8-bit unsigned integer to the buffer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ append() [16/16]

template<typename T, typename... Args, typename = std::enable_if_t<( sizeof...( Args ) > 0 )>>
StringBuilder & nfx::string::StringBuilder::append ( T && first,
Args &&... args )
inline

Append multiple arguments in one call (strings, characters, numeric types).

Template Parameters
TType of the first argument (any type supported by append())
ArgsTypes of the remaining arguments (any type supported by append())
Parameters
firstFirst argument to append
argsRemaining arguments to append
Returns
Reference to this StringBuilder for chaining

Example:

builder.append("User ", userId, " (", userName, ") logged in at ", timestamp);

◆ appendLine() [1/3]

StringBuilder & nfx::string::StringBuilder::appendLine ( const char * str)
inline

Appends null-terminated C-string followed by a newline character.

Parameters
strNull-terminated C-string to append (null pointer handled gracefully)
Returns
Reference to this StringBuilder for chaining

◆ appendLine() [2/3]

StringBuilder & nfx::string::StringBuilder::appendLine ( const std::string & str)
inline

Appends std::string contents followed by a newline character.

Parameters
strString to append
Returns
Reference to this StringBuilder for chaining

◆ appendLine() [3/3]

StringBuilder & nfx::string::StringBuilder::appendLine ( std::string_view str = "")
inline

Appends string_view contents followed by a newline character.

Parameters
strString view to append (default: empty)
Returns
Reference to this StringBuilder for chaining

Efficiently appends the string and newline in one operation. Useful for building line-based formats like logs, CSV, or ISO 19848 messages.

Example:

builder.appendLine("Header")
.appendLine("Data1")
.appendLine("Data2");
// Result: "Header\nData1\nData2\n"

◆ begin() [1/2]

ConstIterator nfx::string::StringBuilder::begin ( ) const
inlinenodiscardnoexcept

Get immutable iterator to beginning of buffer.

Returns
Const iterator pointing to first element

Safe read-only iteration over buffer contents

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ begin() [2/2]

Iterator nfx::string::StringBuilder::begin ( )
inlinenodiscardnoexcept

Get mutable iterator to beginning of buffer.

Returns
Iterator pointing to first element

Enables range-based for loops and STL algorithms

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ capacity()

size_t nfx::string::StringBuilder::capacity ( ) const
inlinenodiscardnoexcept

Get current buffer capacity in bytes.

Returns
Number of bytes allocated for buffer storage

Capacity may be larger than size to avoid frequent reallocations

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ clear()

void nfx::string::StringBuilder::clear ( )
inlinenoexcept

Clear buffer content without deallocating memory.

Sets size to 0 but preserves allocated capacity for reuse

◆ data() [1/2]

const char * nfx::string::StringBuilder::data ( ) const
inlinenodiscardnoexcept

Get immutable pointer to buffer data.

Returns
Const pointer to first byte of buffer data

Safe read-only access to buffer contents

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ data() [2/2]

char * nfx::string::StringBuilder::data ( )
inlinenodiscardnoexcept

Get mutable pointer to buffer data.

Returns
Pointer to first byte of buffer data

Provides direct memory access for high-performance operations

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ end() [1/2]

ConstIterator nfx::string::StringBuilder::end ( ) const
inlinenodiscardnoexcept

Get immutable iterator to end of buffer.

Returns
Const iterator pointing one past last element

Standard STL end iterator semantics

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ end() [2/2]

Iterator nfx::string::StringBuilder::end ( )
inlinenodiscardnoexcept

Get mutable iterator to end of buffer.

Returns
Iterator pointing one past last element

Standard STL end iterator semantics

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ format()

template<typename... Args>
StringBuilder & nfx::string::StringBuilder::format ( std::format_string< Args... > fmt,
Args &&... args )
inline

Format and append text using std::format.

Template Parameters
ArgsTypes of the formatting arguments
Parameters
fmtFormat string with format specifiers
argsArguments to be formatted
Returns
Reference to this StringBuilder for chaining

Provides type-safe formatting directly into the builder without intermediate allocations. Uses std::format_to with back_inserter for optimal performance. Example: builder.format("User {} (ID: {}) logged in at {}", name, userId, timestamp);

◆ isEmpty()

bool nfx::string::StringBuilder::isEmpty ( ) const
inlinenodiscardnoexcept

Check if buffer is empty.

Returns
true if buffer contains no data, false otherwise
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ join() [1/2]

template<typename Container>
StringBuilder & nfx::string::StringBuilder::join ( const Container & items,
char delimiter )
inline

Join container elements with character delimiter.

Template Parameters
ContainerContainer type (vector, array, list, etc.) with begin()/end()
Parameters
itemsContainer of items to join
delimiterCharacter delimiter to insert between elements
Returns
Reference to this StringBuilder for chaining

Optimized variant for single-character delimiters (e.g., ',', ';', '|').

Example:

std::vector<std::string> fields = {"A", "B", "C"};
builder.join(fields, ','); // "A,B,C"

◆ join() [2/2]

template<typename Container>
StringBuilder & nfx::string::StringBuilder::join ( const Container & items,
std::string_view delimiter )
inline

Join container elements with delimiter.

Template Parameters
ContainerContainer type (vector, array, list, etc.) with begin()/end()
Parameters
itemsContainer of items to join
delimiterDelimiter to insert between elements
Returns
Reference to this StringBuilder for chaining

Appends all container elements separated by delimiter. Works with any container providing iterators and elements convertible to string. Uses append() internally, so supports strings, string_view, and types with operator<<.

Example:

std::vector<std::string> fields = {"GPGGA", "123519", "4807.038", "N"};
builder.join(fields, ","); // "GPGGA,123519,4807.038,N"
std::vector<int> numbers = {1, 2, 3, 4, 5};
builder.join(numbers, ", "); // "1, 2, 3, 4, 5"

◆ operator<<() [1/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( char c)
inline

Stream operator for single character.

Parameters
cCharacter to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [2/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( const char * str)
inline

Stream operator for C-string.

Parameters
strNull-terminated C-string to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [3/15]

template<size_t N>
NFX_STRINGBUILDER_FORCE_INLINE StringBuilder & nfx::string::StringBuilder::operator<< ( const char(&) str[N])

Stream operator for string literal (zero strlen overhead).

Template Parameters
NString literal length (deduced by compiler)
Parameters
strString literal
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [4/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( const std::string & str)
inline

Stream operator for std::string.

Parameters
strString to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [5/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( double value)
inline

Stream operator for double-precision floating-point.

Parameters
valueFloating-point value to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [6/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( float value)
inline

Stream operator for single-precision floating-point.

Parameters
valueFloating-point value to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [7/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( std::int16_t value)
inline

Stream operator for 16-bit signed integer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [8/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( std::int32_t value)
inline

Stream operator for 32-bit signed integer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [9/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( std::int64_t value)
inline

Stream operator for 64-bit signed integer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [10/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( std::int8_t value)
inline

Stream operator for 8-bit signed integer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [11/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( std::string_view str)
inline

Stream operator for string_view.

Parameters
strString view to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [12/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( std::uint16_t value)
inline

Stream operator for 16-bit unsigned integer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [13/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( std::uint32_t value)
inline

Stream operator for 32-bit unsigned integer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [14/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( std::uint64_t value)
inline

Stream operator for 64-bit unsigned integer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [15/15]

StringBuilder & nfx::string::StringBuilder::operator<< ( std::uint8_t value)
inline

Stream operator for 8-bit unsigned integer.

Parameters
valueInteger value to append
Returns
Reference to this StringBuilder for chaining

◆ operator=() [1/2]

StringBuilder & nfx::string::StringBuilder::operator= ( const StringBuilder & other)

Copy assignment operator.

Parameters
otherThe StringBuilder to copy from
Returns
Reference to this StringBuilder after assignment

◆ operator=() [2/2]

StringBuilder & nfx::string::StringBuilder::operator= ( StringBuilder && other)
noexcept

Move assignment operator.

Parameters
otherThe StringBuilder to move from
Returns
Reference to this StringBuilder after assignment

◆ operator[]() [1/2]

char & nfx::string::StringBuilder::operator[] ( size_t index)
inline

Access buffer element by index (mutable).

Parameters
indexZero-based index of element to access
Returns
Reference to element at specified index

No bounds checking - undefined behavior if index >= size()

◆ operator[]() [2/2]

const char & nfx::string::StringBuilder::operator[] ( size_t index) const
inline

Access buffer element by index (immutable).

Parameters
indexZero-based index of element to access
Returns
Const reference to element at specified index

No bounds checking - undefined behavior if index >= size()

◆ prepend() [1/14]

StringBuilder & nfx::string::StringBuilder::prepend ( char c)
inline

Prepends single character to the buffer.

Parameters
cCharacter to prepend
Returns
Reference to this StringBuilder for chaining

◆ prepend() [2/14]

StringBuilder & nfx::string::StringBuilder::prepend ( const char * str)
inline

Prepends null-terminated C-string to the buffer.

Parameters
strNull-terminated C-string to prepend (null pointer handled gracefully)
Returns
Reference to this StringBuilder for chaining

◆ prepend() [3/14]

StringBuilder & nfx::string::StringBuilder::prepend ( const std::string & str)
inline

Prepends std::string contents to the buffer.

Parameters
strString to prepend
Returns
Reference to this StringBuilder for chaining

◆ prepend() [4/14]

StringBuilder & nfx::string::StringBuilder::prepend ( double value)
inline

Prepends double-precision floating-point to the buffer.

Parameters
valueFloating-point value to prepend
Returns
Reference to this StringBuilder for chaining

◆ prepend() [5/14]

StringBuilder & nfx::string::StringBuilder::prepend ( float value)
inline

Prepends single-precision floating-point to the buffer.

Parameters
valueFloating-point value to prepend
Returns
Reference to this StringBuilder for chaining

◆ prepend() [6/14]

StringBuilder & nfx::string::StringBuilder::prepend ( std::int16_t value)
inline

Prepends 16-bit signed integer to the buffer.

Parameters
valueInteger value to prepend
Returns
Reference to this StringBuilder for chaining

◆ prepend() [7/14]

StringBuilder & nfx::string::StringBuilder::prepend ( std::int32_t value)
inline

Prepends 32-bit signed integer to the buffer.

Parameters
valueInteger value to prepend
Returns
Reference to this StringBuilder for chaining

◆ prepend() [8/14]

StringBuilder & nfx::string::StringBuilder::prepend ( std::int64_t value)
inline

Prepends 64-bit signed integer to the buffer.

Parameters
valueInteger value to prepend
Returns
Reference to this StringBuilder for chaining

◆ prepend() [9/14]

StringBuilder & nfx::string::StringBuilder::prepend ( std::int8_t value)
inline

Prepends 8-bit signed integer to the buffer.

Parameters
valueInteger value to prepend
Returns
Reference to this StringBuilder for chaining

◆ prepend() [10/14]

StringBuilder & nfx::string::StringBuilder::prepend ( std::string_view str)

Prepends string_view contents to the buffer.

Parameters
strString view to prepend
Returns
Reference to this StringBuilder for chaining

Shifts existing content and inserts at the beginning. Performance: O(n) due to memory shift operation.

◆ prepend() [11/14]

StringBuilder & nfx::string::StringBuilder::prepend ( std::uint16_t value)
inline

Prepends 16-bit unsigned integer to the buffer.

Parameters
valueInteger value to prepend
Returns
Reference to this StringBuilder for chaining

◆ prepend() [12/14]

StringBuilder & nfx::string::StringBuilder::prepend ( std::uint32_t value)
inline

Prepends 32-bit unsigned integer to the buffer.

Parameters
valueInteger value to prepend
Returns
Reference to this StringBuilder for chaining

◆ prepend() [13/14]

StringBuilder & nfx::string::StringBuilder::prepend ( std::uint64_t value)
inline

Prepends 64-bit unsigned integer to the buffer.

Parameters
valueInteger value to prepend
Returns
Reference to this StringBuilder for chaining

◆ prepend() [14/14]

StringBuilder & nfx::string::StringBuilder::prepend ( std::uint8_t value)
inline

Prepends 8-bit unsigned integer to the buffer.

Parameters
valueInteger value to prepend
Returns
Reference to this StringBuilder for chaining

◆ push_back()

void nfx::string::StringBuilder::push_back ( char c)
inline

Appends single character to the buffer (for STL compatibility).

Parameters
cCharacter to append

Inline alias for append(char) to support std::back_inserter

◆ reserve()

void nfx::string::StringBuilder::reserve ( size_t newCapacity)
inline

Reserve minimum capacity for buffer.

Parameters
newCapacityMinimum desired capacity in bytes

May allocate more than requested for efficiency

Exceptions
std::bad_allocif memory allocation fails

◆ resize()

void nfx::string::StringBuilder::resize ( size_t newSize)
inline

Resize buffer to specified size.

Parameters
newSizeNew buffer size in bytes

May truncate content or extend with undefined bytes

Exceptions
std::bad_allocif memory allocation fails

◆ size()

size_t nfx::string::StringBuilder::size ( ) const
inlinenodiscardnoexcept

Get current buffer size in bytes.

Returns
Number of bytes currently stored in buffer

Returns actual content size, not allocated capacity

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ toString() [1/2]

std::string nfx::string::StringBuilder::toString ( ) &&
nodiscard

Convert buffer to string by moving (rvalue-qualified).

Returns
std::string with moved heap buffer or copied stack buffer

For heap buffers, transfers ownership without copying. For stack buffers, performs a copy. Resets builder to empty state after move.

◆ toString() [2/2]

std::string nfx::string::StringBuilder::toString ( ) const &
inlinenodiscard

Convert buffer content to std::string.

Returns
String copy of buffer content

Creates new string object - consider toStringView() for read-only access

◆ toStringView()

std::string_view nfx::string::StringBuilder::toStringView ( ) const
inlinenodiscardnoexcept

Get string_view of buffer content.

Returns
String view referencing buffer data

Zero-copy access - view becomes invalid if buffer is modified

Note
This function is marked [[nodiscard]] - the return value should not be ignored

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