TStringBuilderBase

String Builder

Choose your operating system:

Windows

macOS

Linux

Inheritance Hierarchy

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Containers/StringFwd.h

Include

#include "Containers/StringFwd.h"

Syntax

template<typename CharType>
class TStringBuilderBase

Remarks

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.

Variables

Name Description

Protected variable

CharType *

 

Base

Protected variable

bool

 

bIsDynamic

Protected variable

CharType *

 

CurPos

Protected variable

CharType *

 

End

Constructors

Name Description

Public function

TStringBuilderBase()

Public function

TStringBuilderBase

(
    const TStringBuilderBase&
)

Public function

TStringBuilderBase

(
    TStringBuilderBase&&
)

Public function

TStringBuilderBase

(
    CharType* BufferPointer,
    int32 BufferCapacity
)

Destructors

Name Description

Public function

~TStringBuilderBase()

Functions

Name Description

Public function

int32

 

AddUninitialized

(
    int32 InCount
)

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

Protected function

void *

 

AllocBuffer

(
    SIZE_T CharCount
)

Public function

auto

 

Append

(
    CharRangeType&& Range
)

Public function

BuilderType ...

 

Append

(
    const OtherCharType*const Stri...,
    const int32 Length
)

Public function

BuilderType ...

 

AppendChar

(
    CharType Char
)

Public function

BuilderType ...

 

Appendf

(
    const FmtType& Fmt,
    Types... Args
)

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

Protected function

void

 

EnsureAdditionalCapacity

(
    int32 RequiredAdditionalCapacity
)

Protected function Const

void

 

EnsureNulTerminated()

Protected function

void

 

Extend

(
    SIZE_T ExtraCapacity
)

Protected function

void

 

FreeBuffer

(
    void* Buffer,
    SIZE_T CharCount
)

Public function Const

SIZE_T

 

GetAllocatedSize()

Helper function to return the amount of memory allocated by this container.

Public function Const

const CharTy...

 

GetData()

Public function

CharType ...

 

GetData()

Protected function

void

 

Initialize

(
    CharType* InBase,
    int32 InCapacity
)

Public function

void

 

InsertAt

(
    int32 Pos,
    ViewType Str
)

Insert substring at given position

Public function

BuilderType ...

 

Join

(
    RangeType&& InRange,
    DelimiterType&& InDelimiter
)

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

Public function

BuilderType ...

 

JoinQuoted

(
    RangeType&& InRange,
    DelimiterType&& InDelimiter,
    QuoteType&& InQuote
)

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.

Public function Const

const CharTy...

 

LastChar()

Public function Const

int32

 

Len()

Public function

void

 

Prepend

(
    ViewType Str
)

Insert prefix

Public function

void

 

RemoveAt

(
    int32 Pos,
    int32 RemoveLen
)

Remove characters at given position

Public function

void

 

RemoveSuffix

(
    int32 InCount
)

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

Public function

void

 

ReplaceAt

(
    int32 Pos,
    int32 RemoveLen,
    ViewType Str
)

Replace characters at given position and length with substring

Public function

void

 

Reset()

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

Public function Const

const CharTy...

 

ToString()

Public function Const

ViewType

 

ToView()

Operators

Name Description

Public function Const

const CharTy...

 

operator*()

Public function

TStringBuild...

 

operator=

(
    const CharType* Str
)

Public function

TStringBuild...

 

operator=

(
    ViewType Str
)

Public function

TStringBuild...

 

operator=

(
    TStringBuilderBase&&
)

Public function

TStringBuild...

 

operator=

(
    const TStringBuilderBase&
)

Typedefs

Name

Description

BuilderType

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

ElementType

The character type that this builder operates on.

TCanAppend

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

TCanAppendRange

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

ViewType

The string view type that this builder is compatible with.

Constants

Name

Description

EmptyBuffer

Deprecated Functions

Name Description

Public function

BuilderType ...

 

Append

(
    CharType Char
)

Use AppendChar instead of Append.

Public function

BuilderType ...

 

AppendAnsi

(
    const ANSICHAR*const String,
    const int32 Length
)

Use Append instead of AppendAnsi.

Public function

BuilderType ...

 

AppendAnsi

(
    const ANSICHAR*const String
)

Use Append instead of AppendAnsi.

Public function

BuilderType ...

 

AppendAnsi

(
    const FAnsiStringView String
)

Use Append instead of AppendAnsi.