nfx-stringbuilder 0.1.1
High-performance C++20 library for zero-allocation string building with thread-safe pooling
Loading...
Searching...
No Matches
nfx::string::StringBuilder Class Referencefinal

High-performance string builder with fluent interface and 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 ()=delete
 Default constructor.
 StringBuilder (const StringBuilder &)=default
 Copy constructor.
 StringBuilder (StringBuilder &&) noexcept=delete
 Move constructor.
 ~StringBuilder ()=default
 Destructor.
StringBuilder & operator= (const StringBuilder &)=delete
 Copy assignment operator.
StringBuilder & operator= (StringBuilder &&) noexcept=delete
 Move assignment operator.
char & operator[] (size_t index)
 Provides read-write access to character at specified index.
const char & operator[] (size_t index) const
 Provides read-only access to character at specified index.
void append (std::string_view str)
 Appends string_view contents to the buffer efficiently.
void append (const std::string &str)
 Appends std::string contents to the buffer.
void append (const char *str)
 Appends null-terminated C-string to the buffer.
void append (char c)
 Appends single character to the buffer.
StringBuilder & operator<< (std::string_view str)
 Stream operator for string_view.
StringBuilder & operator<< (const std::string &str)
 Stream operator for std::string.
StringBuilder & operator<< (const char *str)
 Stream operator for C-string.
StringBuilder & operator<< (char c)
 Stream operator for single character.
StringBuilder & operator<< (std::int32_t value)
 Stream operator for 32-bit signed integer.
StringBuilder & operator<< (std::uint32_t value)
 Stream operator for 32-bit unsigned integer.
StringBuilder & operator<< (std::int64_t value)
 Stream operator for 64-bit signed integer.
StringBuilder & operator<< (std::uint64_t value)
 Stream operator for 64-bit unsigned integer.
StringBuilder & operator<< (float value)
 Stream operator for single-precision floating-point.
StringBuilder & operator<< (double value)
 Stream operator for double-precision floating-point.
template<typename... Args>
StringBuilder & format (std::format_string< Args... > fmt, Args &&... args)
 Format and append text using std::format.
size_t length () const noexcept
 Returns current buffer size in characters.
void resize (size_t newSize)
 Resizes buffer to specified character count.
Iterator begin ()
 Returns mutable iterator to beginning of character sequence.
ConstIterator begin () const
 Returns const iterator to beginning of character sequence.
Iterator end ()
 Returns mutable iterator to end of character sequence.
ConstIterator end () const
 Returns const iterator to end of character sequence.

Friends

class StringBuilderLease
class std::back_insert_iterator< StringBuilder >

Detailed Description

High-performance string builder with fluent interface and efficient memory management.

Provides a convenient wrapper around DynamicStringBuffer with stream-like operators for intuitive string construction. Features efficient append operations, iterator support, and automatic memory management through the underlying buffer.

Note
This class is a lightweight wrapper that references an underlying DynamicStringBuffer. It does not own the buffer memory - use StringBuilderPool::lease() for proper RAII management.
Warning
Not thread-safe - external synchronization required for concurrent access. Multiple StringBuilder instances should not reference the same buffer concurrently.
See also
StringBuilderPool for the recommended way to obtain StringBuilder instances
StringBuilderLease for RAII management of pooled buffers
DynamicStringBuffer for the underlying buffer implementation

Definition at line 429 of file StringBuilder.h.

Member Typedef Documentation

◆ const_iterator

Type alias for const iterator.

Definition at line 638 of file StringBuilder.h.

◆ ConstIterator

Immutable iterator type for buffer traversal.

Definition at line 632 of file StringBuilder.h.

◆ Iterator

Mutable iterator type for buffer traversal.

Definition at line 629 of file StringBuilder.h.

◆ iterator

Type alias for iterator.

Definition at line 635 of file StringBuilder.h.

◆ value_type

Character type for iterator compatibility.

Definition at line 626 of file StringBuilder.h.

Member Function Documentation

◆ append() [1/4]

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

Appends single character to the buffer.

Parameters
cCharacter to append
Here is the call graph for this function:

◆ append() [2/4]

void 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)
Here is the call graph for this function:

◆ append() [3/4]

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

Appends std::string contents to the buffer.

Parameters
strString to append
Here is the call graph for this function:

◆ append() [4/4]

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

Appends string_view contents to the buffer efficiently.

Parameters
strString view to append
Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [1/2]

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

Returns mutable iterator to beginning of character sequence.

Returns
Iterator pointing to the first character in the buffer
Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [2/2]

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

Returns const iterator to beginning of character sequence.

Returns
Const iterator pointing to the first character in the buffer
Here is the call graph for this function:

◆ end() [1/2]

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

Returns mutable iterator to end of character sequence.

Returns
Iterator pointing one past the last character in the buffer
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end() [2/2]

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

Returns const iterator to end of character sequence.

Returns
Const iterator pointing one past the last character in the buffer
Here is the call graph for this function:

◆ 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);

Here is the call graph for this function:
Here is the caller graph for this function:

◆ length()

size_t nfx::string::StringBuilder::length ( ) const
inlinenoexcept

Returns current buffer size in characters.

Returns
Number of characters currently stored in the buffer
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<() [1/10]

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/10]

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/10]

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<<() [4/10]

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<<() [5/10]

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<<() [6/10]

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<<() [7/10]

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<<() [8/10]

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<<() [9/10]

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<<() [10/10]

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[]() [1/2]

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

Provides read-write access to character at specified index.

Parameters
indexZero-based character index
Returns
Reference to character at the specified position

◆ operator[]() [2/2]

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

Provides read-only access to character at specified index.

Parameters
indexZero-based character index
Returns
Const reference to character at the specified position

◆ resize()

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

Resizes buffer to specified character count.

Parameters
newSizeNew buffer size in characters
Here is the call graph for this function:
Here is the caller graph for this function:

◆ std::back_insert_iterator< StringBuilder >

friend class std::back_insert_iterator< StringBuilder >
friend

Definition at line 431 of file StringBuilder.h.

◆ StringBuilderLease

friend class StringBuilderLease
friend

Definition at line 431 of file StringBuilder.h.


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