UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TStringBuilderBase< CharType > Class Template Reference

#include <StringBuilder.h>

+ Inheritance diagram for TStringBuilderBase< CharType >:

Public Types

using ElementType = CharType
 
using BuilderType = TStringBuilderBase< ElementType >
 
using ViewType = TStringView< ElementType >
 

Public Member Functions

 TStringBuilderBase ()=default
 
CORE_API ~TStringBuilderBase ()
 
 TStringBuilderBase (const TStringBuilderBase &)=delete
 
 TStringBuilderBase (TStringBuilderBase &&)=delete
 
TStringBuilderBaseoperator= (const TStringBuilderBase &)=delete
 
TStringBuilderBaseoperator= (TStringBuilderBase &&)=delete
 
TStringBuilderBaseoperator= (ViewType Str)
 
TStringBuilderBaseoperator= (const CharType *Str)
 
 TStringBuilderBase (CharType *BufferPointer, int32 BufferCapacity)
 
int32 Len () const
 
CharType * GetData () UE_LIFETIMEBOUND
 
const CharType * GetData () const UE_LIFETIMEBOUND
 
const CharType * ToString () UE_LIFETIMEBOUND
 
const CharType * ToString () const UE_LIFETIMEBOUND
 
const CharType * operator* () UE_LIFETIMEBOUND
 
const CharType * operator* () const UE_LIFETIMEBOUND
 
ViewType ToView () const UE_LIFETIMEBOUND
 
CharType LastChar () const
 
SIZE_T GetAllocatedSize () const
 
void Reset ()
 
int32 AddUninitialized (int32 InCount)
 
void Reserve (int32 InNewCapacity)
 
void RemoveSuffix (int32 InCount)
 
template<typename OtherCharType , std::enable_if_t< TIsCharType< OtherCharType >::Value > * = nullptr>
BuilderTypeAppend (const OtherCharType *const String, const int32 Length)
 
template<typename CharRangeType >
auto Append (CharRangeType &&Range) -> decltype(Append(MakeStringView(Forward< CharRangeType >(Range)).GetData(), int32(0)))
 
template<typename AppendedCharType , std::enable_if_t< TIsCharType< AppendedCharType >::Value > * = nullptr>
BuilderTypeAppendChar (AppendedCharType Char)
 
void ReplaceAt (int32 Pos, int32 RemoveLen, ViewType Str)
 
void InsertAt (int32 Pos, ViewType Str)
 
void RemoveAt (int32 Pos, int32 RemoveLen)
 
void Prepend (ViewType Str)
 
template<typename AppendedCharType >
auto Add (AppendedCharType Char) -> decltype(AppendChar(Char),(void) 0)
 
template<typename RangeType , typename DelimiterType >
requires requires (BuilderType& Builder, RangeType&& Range, const DelimiterType& Delimiter) { Builder << *std::begin(Range); Builder << Delimiter; }
BuilderTypeJoin (RangeType &&InRange, const DelimiterType &InDelimiter)
 
template<typename RangeType , typename DelimiterType , typename QuoteType >
requires requires (BuilderType& Builder, RangeType&& Range, const DelimiterType& Delimiter, const QuoteType& Quote) { Builder << Quote << *std::begin(Range) << Quote; Builder << Delimiter; }
BuilderTypeJoinQuoted (RangeType &&InRange, const DelimiterType &InDelimiter, const QuoteType &InQuote)
 
template<typename FmtType , typename... Types UE_REQUIRES>
BuilderTypeAppendf (const FmtType &Fmt, Types... Args)
 
CORE_API BuilderTypeAppendV (const CharType *Fmt, va_list Args)
 

Protected Member Functions

 TStringBuilderBase (CharType *InBase, int32 InCapacity, UE::Core::Private::FDynamicStringBuilderToken)
 
 TStringBuilderBase (CharType *InBase, int32 InCapacity, UE::Core::Private::FExternalStringBuilderToken)
 
void Initialize (CharType *InBase, int32 InCapacity)
 
void EnsureNulTerminated ()
 
void EnsureAdditionalCapacity (int32 RequiredAdditionalCapacity)
 
CORE_API void Extend (SIZE_T ExtraCapacity)
 
voidAllocBuffer (SIZE_T CharCount)
 
void FreeBuffer (void *Buffer)
 

Protected Attributes

CharType * Base = nullptr
 
CharType * CurPos = nullptr
 
CharType * End = nullptr
 
bool bIsDynamic = false
 
bool bIsExternal = false
 

Friends

CharType * begin (TStringBuilderBase &Builder)
 
const CharType * begin (const TStringBuilderBase &Builder)
 
CharType * end (TStringBuilderBase &Builder)
 
const CharType * end (const TStringBuilderBase &Builder)
 

Detailed Description

template<typename CharType>
class TStringBuilderBase< CharType >

String Builder

This class helps with the common task of constructing new strings.

It does this by allocating buffer space which is used to hold the constructed string. The intent is that the builder is allocated on the stack as a function local variable to avoid heap allocations.

The buffer is always contiguous and the class is not intended to be used to construct extremely large strings.

This is not intended to be used as a mechanism for holding on to strings for a long time. The use case is explicitly to aid in constructing strings on the stack and subsequently passing the string into a function call or a more permanent string storage mechanism like FString et al.

The amount of buffer space to allocate is specified via a template parameter and if the constructed string should overflow this initial buffer, a new buffer will be allocated using regular dynamic memory allocations.

Overflow allocation should be the exceptional case however – always try to size the buffer so that it can hold the vast majority of strings you expect to construct.

Be mindful that stack is a limited resource, so if you are writing a highly recursive function you may want to use some other mechanism to build your strings.

Member Typedef Documentation

◆ BuilderType

template<typename CharType >
using TStringBuilderBase< CharType >::BuilderType = TStringBuilderBase<ElementType>

The string builder base type to be used by append operators and function output parameters.

◆ ElementType

template<typename CharType >
using TStringBuilderBase< CharType >::ElementType = CharType

The character type that this builder operates on.

◆ ViewType

template<typename CharType >
using TStringBuilderBase< CharType >::ViewType = TStringView<ElementType>

The string view type that this builder is compatible with.

Constructor & Destructor Documentation

◆ TStringBuilderBase() [1/6]

template<typename CharType >
TStringBuilderBase< CharType >::TStringBuilderBase ( )
default

◆ ~TStringBuilderBase()

◆ TStringBuilderBase() [2/6]

template<typename CharType >
TStringBuilderBase< CharType >::TStringBuilderBase ( const TStringBuilderBase< CharType > &  )
delete

◆ TStringBuilderBase() [3/6]

template<typename CharType >
TStringBuilderBase< CharType >::TStringBuilderBase ( TStringBuilderBase< CharType > &&  )
delete

◆ TStringBuilderBase() [4/6]

template<typename CharType >
TStringBuilderBase< CharType >::TStringBuilderBase ( CharType *  BufferPointer,
int32  BufferCapacity 
)
inline

◆ TStringBuilderBase() [5/6]

template<typename CharType >
TStringBuilderBase< CharType >::TStringBuilderBase ( CharType *  InBase,
int32  InCapacity,
UE::Core::Private::FDynamicStringBuilderToken   
)
inlineprotected

◆ TStringBuilderBase() [6/6]

template<typename CharType >
TStringBuilderBase< CharType >::TStringBuilderBase ( CharType *  InBase,
int32  InCapacity,
UE::Core::Private::FExternalStringBuilderToken   
)
inlineprotected

Member Function Documentation

◆ Add()

template<typename CharType >
auto TStringBuilderBase< CharType >::Add ( AppendedCharType  Char) -> decltype(AppendChar(Char), (void)0)
inline

Prefer AppendChar. Appends one character to the string. Supports this being the output for Algo::...

◆ AddUninitialized()

template<typename CharType >
int32 TStringBuilderBase< CharType >::AddUninitialized ( int32  InCount)
inline

Adds a given number of uninitialized characters into the string builder.

Parameters
InCountThe number of uninitialized characters to add.
Returns
The number of characters in the string builder before adding the new characters.

◆ AllocBuffer()

template<typename C >
void * TStringBuilderBase< C >::AllocBuffer ( SIZE_T  CharCount)
inlineprotected

◆ Append() [1/2]

template<typename CharType >
template<typename CharRangeType >
auto TStringBuilderBase< CharType >::Append ( CharRangeType &&  Range) -> decltype(Append(MakeStringView(Forward<CharRangeType>(Range)).GetData(), int32(0)))
inline

◆ Append() [2/2]

template<typename CharType >
template<typename OtherCharType , std::enable_if_t< TIsCharType< OtherCharType >::Value > * = nullptr>
BuilderType & TStringBuilderBase< CharType >::Append ( const OtherCharType *const  String,
const int32  Length 
)
inline

◆ AppendChar()

template<typename CharType >
template<typename AppendedCharType , std::enable_if_t< TIsCharType< AppendedCharType >::Value > * = nullptr>
BuilderType & TStringBuilderBase< CharType >::AppendChar ( AppendedCharType  Char)
inline

◆ Appendf()

template<typename CharType >
template<typename FmtType , typename... Types UE_REQUIRES>
BuilderType & TStringBuilderBase< CharType >::Appendf ( const FmtType Fmt,
Types...  Args 
)
inline

Appends to the string builder similarly to how classic sprintf works.

Parameters
FmtA format string that specifies how to format the additional arguments. Refer to standard printf format.

◆ AppendV()

template<typename CharType >
TStringBuilderBase< C > & TStringBuilderBase< C >::AppendV ( const CharType *  Fmt,
va_list  Args 
)

Appends to the string builder similarly to how classic vsprintf works.

Parameters
FmtA format string that specifies how to format the additional arguments. Refer to standard printf format.

◆ EnsureAdditionalCapacity()

template<typename CharType >
void TStringBuilderBase< CharType >::EnsureAdditionalCapacity ( int32  RequiredAdditionalCapacity)
inlineprotected

◆ EnsureNulTerminated()

template<typename CharType >
void TStringBuilderBase< CharType >::EnsureNulTerminated ( )
inlineprotected

◆ Extend()

template<typename C >
void TStringBuilderBase< C >::Extend ( SIZE_T  ExtraCapacity)
protected

◆ FreeBuffer()

template<typename C >
void TStringBuilderBase< C >::FreeBuffer ( void Buffer)
inlineprotected

◆ GetAllocatedSize()

template<typename CharType >
SIZE_T TStringBuilderBase< CharType >::GetAllocatedSize ( ) const
inline

Helper function to return the amount of memory allocated by this container. Does not include the sizeof of the inline buffer, only includes the size of the overflow buffer.

Returns
Number of bytes allocated by this container.

◆ GetData() [1/2]

template<typename CharType >
const CharType * TStringBuilderBase< CharType >::GetData ( ) const
inline

◆ GetData() [2/2]

template<typename CharType >
CharType * TStringBuilderBase< CharType >::GetData ( )
inline

Returns a pointer to Len() code units that are not necessarily null-terminated.

◆ Initialize()

template<typename CharType >
void TStringBuilderBase< CharType >::Initialize ( CharType *  InBase,
int32  InCapacity 
)
inlineprotected

◆ InsertAt()

template<typename CharType >
void TStringBuilderBase< CharType >::InsertAt ( int32  Pos,
ViewType  Str 
)
inline

Insert substring at given position

◆ Join()

template<typename CharType >
template<typename RangeType , typename DelimiterType >
requires requires (BuilderType& Builder, RangeType&& Range, const DelimiterType& Delimiter) { Builder << *std::begin(Range); Builder << Delimiter; }
BuilderType & TStringBuilderBase< CharType >::Join ( RangeType &&  InRange,
const DelimiterType InDelimiter 
)
inline

Append every element of the range to the builder, separating the elements by the delimiter.

This function is only available when the elements of the range and the delimiter can both be written to the builder using the append operator.

Parameters
InRangeThe range of elements to join and append.
InDelimiterThe delimiter to append as a separator for the elements.
Returns
The builder, to allow additional operations to be composed with this one.

◆ JoinQuoted()

template<typename CharType >
template<typename RangeType , typename DelimiterType , typename QuoteType >
requires requires (BuilderType& Builder, RangeType&& Range, const DelimiterType& Delimiter, const QuoteType& Quote) { Builder << Quote << *std::begin(Range) << Quote; Builder << Delimiter; }
BuilderType & TStringBuilderBase< CharType >::JoinQuoted ( RangeType &&  InRange,
const DelimiterType InDelimiter,
const QuoteType InQuote 
)
inline

Append every element of the range to the builder, separating the elements by the delimiter, and surrounding every element on each side with the given quote.

This function is only available when the elements of the range, the delimiter, and the quote can be written to the builder using the append operator.

Parameters
InRangeThe range of elements to join and append.
InDelimiterThe delimiter to append as a separator for the elements.
InQuoteThe quote to append on both sides of each element.
Returns
The builder, to allow additional operations to be composed with this one.

◆ LastChar()

template<typename CharType >
CharType TStringBuilderBase< CharType >::LastChar ( ) const
inline

Returns the last character, technically the last code unit.

◆ Len()

template<typename CharType >
int32 TStringBuilderBase< CharType >::Len ( ) const
inline

◆ operator*() [1/2]

template<typename CharType >
const CharType * TStringBuilderBase< CharType >::operator* ( ) const
inline

Returns a pointer to a null-terminated string that is valid until the builder is mutated.

◆ operator*() [2/2]

template<typename CharType >
const CharType * TStringBuilderBase< CharType >::operator* ( )
inline

Returns a pointer to a null-terminated string that is valid until the builder is mutated.

◆ operator=() [1/4]

template<typename CharType >
TStringBuilderBase & TStringBuilderBase< CharType >::operator= ( const CharType *  Str)
inline

◆ operator=() [2/4]

template<typename CharType >
TStringBuilderBase & TStringBuilderBase< CharType >::operator= ( const TStringBuilderBase< CharType > &  )
delete

◆ operator=() [3/4]

template<typename CharType >
TStringBuilderBase & TStringBuilderBase< CharType >::operator= ( TStringBuilderBase< CharType > &&  )
delete

◆ operator=() [4/4]

template<typename CharType >
TStringBuilderBase & TStringBuilderBase< CharType >::operator= ( ViewType  Str)
inline

◆ Prepend()

template<typename CharType >
void TStringBuilderBase< CharType >::Prepend ( ViewType  Str)
inline

Insert prefix

◆ RemoveAt()

template<typename CharType >
void TStringBuilderBase< CharType >::RemoveAt ( int32  Pos,
int32  RemoveLen 
)
inline

Remove characters at given position

◆ RemoveSuffix()

template<typename CharType >
void TStringBuilderBase< CharType >::RemoveSuffix ( int32  InCount)
inline

Modifies the string builder to remove the given number of characters from the end.

◆ ReplaceAt()

template<typename CharType >
void TStringBuilderBase< CharType >::ReplaceAt ( int32  Pos,
int32  RemoveLen,
ViewType  Str 
)
inline

Replace characters at given position and length with substring

◆ Reserve()

template<typename CharType >
void TStringBuilderBase< CharType >::Reserve ( int32  InNewCapacity)
inline

Reserves memory such that the string builder can contain at least the given number of characters.

Note
: Unlike AddUninitialized, this will not advance CurPos, and thus the various Append calls will start at the end of the string builder (from prior to this Reserve call).
Parameters
InNewCapacityThe total number of characters the string builder can contain.

◆ Reset()

template<typename CharType >
void TStringBuilderBase< CharType >::Reset ( )
inline

Empties the string builder, but doesn't change memory allocation.

◆ ToString() [1/2]

template<typename CharType >
const CharType * TStringBuilderBase< CharType >::ToString ( ) const
inline

Prefer operator*() for a pointer to a null-terminated string.

◆ ToString() [2/2]

template<typename CharType >
const CharType * TStringBuilderBase< CharType >::ToString ( )
inline

Prefer operator*() for a pointer to a null-terminated string.

Construct FString and other string types directly from the string builder: FString Str(Builder).

◆ ToView()

template<typename CharType >
ViewType TStringBuilderBase< CharType >::ToView ( ) const
inline

Returns a view of the string that is valid until the builder is mutated.

Friends And Related Symbol Documentation

◆ begin [1/2]

template<typename CharType >
const CharType * begin ( const TStringBuilderBase< CharType > &  Builder)
friend

◆ begin [2/2]

template<typename CharType >
CharType * begin ( TStringBuilderBase< CharType > &  Builder)
friend

◆ end [1/2]

template<typename CharType >
const CharType * end ( const TStringBuilderBase< CharType > &  Builder)
friend

◆ end [2/2]

template<typename CharType >
CharType * end ( TStringBuilderBase< CharType > &  Builder)
friend

Member Data Documentation

◆ Base

template<typename CharType >
CharType* TStringBuilderBase< CharType >::Base = nullptr
protected

◆ bIsDynamic

template<typename CharType >
bool TStringBuilderBase< CharType >::bIsDynamic = false
protected

◆ bIsExternal

template<typename CharType >
bool TStringBuilderBase< CharType >::bIsExternal = false
protected

◆ CurPos

template<typename CharType >
CharType* TStringBuilderBase< CharType >::CurPos = nullptr
protected

◆ End

template<typename CharType >
CharType* TStringBuilderBase< CharType >::End = nullptr
protected

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