Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
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
 
 ~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 ()
 
const CharType * GetData () const
 
const CharType * ToString () const
 
ViewType ToView () const
 
const CharType * operator* () const
 
const CharType LastChar () const
 
SIZE_T GetAllocatedSize () const
 
void Reset ()
 
int32 AddUninitialized (int32 InCount)
 
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)
 
template<typename AppendedCharType , std::enable_if_t< TIsCharType< AppendedCharType >::Value > * = nullptr>
BuilderTypeAppend (AppendedCharType Char)
 
BuilderTypeAppendAnsi (const FAnsiStringView String)
 
BuilderTypeAppendAnsi (const ANSICHAR *const String)
 
BuilderTypeAppendAnsi (const ANSICHAR *const String, const int32 Length)
 
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 RangeType , typename DelimiterType , std::enable_if_t< TCanAppendRange_V< RangeType && > &&TCanAppend_V< DelimiterType && > > * = nullptr>
BuilderTypeJoin (RangeType &&InRange, DelimiterType &&InDelimiter)
 
template<typename RangeType , typename DelimiterType , typename QuoteType , std::enable_if_t< TCanAppendRange_V< RangeType > &&TCanAppend_V< DelimiterType && > &&TCanAppend_V< QuoteType && > > * = nullptr>
BuilderTypeJoinQuoted (RangeType &&InRange, DelimiterType &&InDelimiter, QuoteType &&InQuote)
 
template<typename FmtType , typename... Types, std::enable_if_t< TIsArrayOrRefOfTypeByPredicate< FmtType, TIsCharEncodingCompatibleWithCharType >::Value > * = nullptr>
BuilderTypeAppendf (const FmtType &Fmt, Types... Args)
 
BuilderTypeAppendV (const CharType *Fmt, va_list Args)
 

Static Public Attributes

template<typename AppendType >
static constexpr bool TCanAppend_V = std::is_same_v<BuilderType&, decltype(DeclVal<BuilderType&>() << DeclVal<AppendType>())>
 
template<typename RangeType >
static constexpr bool TCanAppendRange_V = TIsContiguousContainer<RangeType>::Value && TCanAppend_V<decltype(*::GetData(DeclVal<RangeType>()))>
 

Protected Member Functions

void Initialize (CharType *InBase, int32 InCapacity)
 
void EnsureNulTerminated () const
 
void EnsureAdditionalCapacity (int32 RequiredAdditionalCapacity)
 
void Extend (SIZE_T ExtraCapacity)
 
voidAllocBuffer (SIZE_T CharCount)
 
void FreeBuffer (void *Buffer, SIZE_T CharCount)
 

Protected Attributes

CharType * Base = EmptyBuffer
 
CharType * CurPos = Base
 
CharType * End = Base + 1
 
bool bIsDynamic = false
 

Static Protected Attributes

static CharType EmptyBuffer [1] {}
 

Private Types

template<typename SrcEncoding >
using TIsCharEncodingCompatibleWithCharType = TIsCharEncodingCompatibleWith<SrcEncoding, CharType>
 

Static Private Member Functions

static BuilderType &VARARGS AppendfImpl (BuilderType &Self, const CharType *Fmt,...)
 

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.

Definition at line 59 of file StringBuilder.h.

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.

Definition at line 65 of file StringBuilder.h.

◆ ElementType

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

The character type that this builder operates on.

Definition at line 63 of file StringBuilder.h.

◆ TIsCharEncodingCompatibleWithCharType

template<typename CharType >
template<typename SrcEncoding >
using TStringBuilderBase< CharType >::TIsCharEncodingCompatibleWithCharType = TIsCharEncodingCompatibleWith<SrcEncoding, CharType>
private

Definition at line 323 of file StringBuilder.h.

◆ ViewType

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

The string view type that this builder is compatible with.

Definition at line 67 of file StringBuilder.h.

Constructor & Destructor Documentation

◆ TStringBuilderBase() [1/4]

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

◆ ~TStringBuilderBase()

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

◆ TStringBuilderBase() [2/4]

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

◆ TStringBuilderBase() [3/4]

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

◆ TStringBuilderBase() [4/4]

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

Definition at line 97 of file StringBuilder.h.

Member Function Documentation

◆ 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.

Definition at line 137 of file StringBuilder.h.

◆ AllocBuffer()

template<typename CharType >
void * TStringBuilderBase< CharType >::AllocBuffer ( SIZE_T CharCount)
protected

◆ Append() [1/3]

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

Definition at line 197 of file StringBuilder.h.

◆ Append() [2/3]

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

Definition at line 165 of file StringBuilder.h.

◆ Append() [3/3]

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

Definition at line 156 of file StringBuilder.h.

◆ AppendAnsi() [1/3]

template<typename CharType >
BuilderType & TStringBuilderBase< CharType >::AppendAnsi ( const ANSICHAR *const String)
inline

Definition at line 204 of file StringBuilder.h.

◆ AppendAnsi() [2/3]

template<typename CharType >
BuilderType & TStringBuilderBase< CharType >::AppendAnsi ( const ANSICHAR *const String,
const int32 Length )
inline

Definition at line 206 of file StringBuilder.h.

◆ AppendAnsi() [3/3]

template<typename CharType >
BuilderType & TStringBuilderBase< CharType >::AppendAnsi ( const FAnsiStringView String)
inline

Definition at line 202 of file StringBuilder.h.

◆ AppendChar()

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

Definition at line 175 of file StringBuilder.h.

◆ Appendf()

template<typename CharType >
template<typename FmtType , typename... Types, std::enable_if_t< TIsArrayOrRefOfTypeByPredicate< FmtType, TIsCharEncodingCompatibleWithCharType >::Value > * = nullptr>
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.

Definition at line 333 of file StringBuilder.h.

◆ AppendfImpl()

template<typename CharType >
static BuilderType &VARARGS TStringBuilderBase< CharType >::AppendfImpl ( BuilderType & Self,
const CharType * Fmt,
... )
staticprivate

◆ AppendV()

template<typename CharType >
BuilderType & TStringBuilderBase< CharType >::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

Definition at line 362 of file StringBuilder.h.

◆ EnsureNulTerminated()

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

Definition at line 357 of file StringBuilder.h.

◆ Extend()

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

◆ FreeBuffer()

template<typename CharType >
void TStringBuilderBase< CharType >::FreeBuffer ( void * Buffer,
SIZE_T CharCount )
protected

◆ 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.

Definition at line 117 of file StringBuilder.h.

◆ GetData() [1/2]

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

Definition at line 103 of file StringBuilder.h.

◆ GetData() [2/2]

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

Definition at line 104 of file StringBuilder.h.

◆ Initialize()

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

Definition at line 350 of file StringBuilder.h.

◆ InsertAt()

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

Insert substring at given position

Definition at line 240 of file StringBuilder.h.

◆ Join()

template<typename CharType >
template<typename RangeType , typename DelimiterType , std::enable_if_t< TCanAppendRange_V< RangeType && > &&TCanAppend_V< DelimiterType && > > * = nullptr>
BuilderType & TStringBuilderBase< CharType >::Join ( RangeType && InRange,
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.

Definition at line 270 of file StringBuilder.h.

◆ JoinQuoted()

template<typename CharType >
template<typename RangeType , typename DelimiterType , typename QuoteType , std::enable_if_t< TCanAppendRange_V< RangeType > &&TCanAppend_V< DelimiterType && > &&TCanAppend_V< QuoteType && > > * = nullptr>
BuilderType & TStringBuilderBase< CharType >::JoinQuoted ( RangeType && InRange,
DelimiterType && InDelimiter,
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.

Definition at line 303 of file StringBuilder.h.

◆ LastChar()

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

Definition at line 109 of file StringBuilder.h.

◆ Len()

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

Definition at line 102 of file StringBuilder.h.

◆ operator*()

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

Definition at line 107 of file StringBuilder.h.

◆ operator=() [1/4]

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

Definition at line 92 of file StringBuilder.h.

◆ 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

Definition at line 86 of file StringBuilder.h.

◆ Prepend()

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

Insert prefix

Definition at line 252 of file StringBuilder.h.

◆ RemoveAt()

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

Remove characters at given position

Definition at line 246 of file StringBuilder.h.

◆ 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.

Definition at line 148 of file StringBuilder.h.

◆ ReplaceAt()

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

Replace characters at given position and length with substring

Definition at line 209 of file StringBuilder.h.

◆ Reset()

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

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

Definition at line 125 of file StringBuilder.h.

◆ ToString()

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

Definition at line 105 of file StringBuilder.h.

◆ ToView()

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

Definition at line 106 of file StringBuilder.h.

Member Data Documentation

◆ Base

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

Definition at line 381 of file StringBuilder.h.

◆ bIsDynamic

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

Definition at line 384 of file StringBuilder.h.

◆ CurPos

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

Definition at line 382 of file StringBuilder.h.

◆ EmptyBuffer

template<typename CharType >
CharType TStringBuilderBase< CharType >::EmptyBuffer[1] {}
inlinestaticprotected

Definition at line 379 of file StringBuilder.h.

◆ End

template<typename CharType >
CharType* TStringBuilderBase< CharType >::End = Base + 1
protected

Definition at line 383 of file StringBuilder.h.

◆ TCanAppend_V

template<typename CharType >
template<typename AppendType >
constexpr bool TStringBuilderBase< CharType >::TCanAppend_V = std::is_same_v<BuilderType&, decltype(DeclVal<BuilderType&>() << DeclVal<AppendType>())>
inlinestaticconstexpr

Whether the given type can be appended to this builder using the append operator.

Definition at line 71 of file StringBuilder.h.

◆ TCanAppendRange_V

template<typename CharType >
template<typename RangeType >
constexpr bool TStringBuilderBase< CharType >::TCanAppendRange_V = TIsContiguousContainer<RangeType>::Value && TCanAppend_V<decltype(*::GetData(DeclVal<RangeType>()))>
inlinestaticconstexpr

Whether the given range type can have its elements appended to the builder using the append operator.

Definition at line 75 of file StringBuilder.h.


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