Navigation
API > API/Runtime > API/Runtime/Core
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.
| Name | TStringBuilderBase |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/Misc/StringBuilder.h |
| Include Path | #include "Misc/StringBuilder.h" |
Syntax
template<typename CharType>
class TStringBuilderBase
Derived Classes
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TStringBuilderBase
(
CharType* InBase, |
Misc/StringBuilder.h | ||
| Misc/StringBuilder.h | |||
TStringBuilderBase
(
const TStringBuilderBase& |
Misc/StringBuilder.h | ||
| Misc/StringBuilder.h | |||
TStringBuilderBase
(
CharType* BufferPointer, |
Misc/StringBuilder.h | ||
TStringBuilderBase
(
CharType* InBase, |
Misc/StringBuilder.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
CORE_API ~TStringBuilderBase() |
Misc/StringBuilder.h |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| BuilderType | TStringBuilderBase< ElementType > | The string builder base type to be used by append operators and function output parameters. | Misc/StringBuilder.h |
| ElementType | CharType | The character type that this builder operates on. | Misc/StringBuilder.h |
| TIsCharEncodingCompatibleWithCharType | TIsCharEncodingCompatibleWith< SrcEncoding, CharType > | Misc/StringBuilder.h | |
| ViewType | TStringView< ElementType > | The string view type that this builder is compatible with. | Misc/StringBuilder.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
decltype(AppendChar(Char),(void) 0) Add
(
AppendedCharType Char |
Prefer AppendChar. | Misc/StringBuilder.h | |
int32 AddUninitialized
(
int32 InCount |
Adds a given number of uninitialized characters into the string builder. | Misc/StringBuilder.h | |
BuilderType & Append
(
const OtherCharType*const String, |
Misc/StringBuilder.h | ||
decltype(Append(MakeStringView(Forward< CharRangeType >(Range)).GetData(), int32(0))) Append
(
CharRangeType&& Range |
Misc/StringBuilder.h | ||
BuilderType & AppendChar
(
AppendedCharType Char |
Misc/StringBuilder.h | ||
BuilderType & Appendf
(
const FmtType& Fmt, |
Appends to the string builder similarly to how classic sprintf works. | Misc/StringBuilder.h | |
BuilderType & AppendV
(
const CharType* Fmt, |
Appends to the string builder similarly to how classic vsprintf works. | Misc/StringBuilder.h | |
SIZE_T GetAllocatedSize () |
Helper function to return the amount of memory allocated by this container. | Misc/StringBuilder.h | |
const CharType * GetData () |
Misc/StringBuilder.h | ||
CharType * GetData () |
Returns a pointer to Len() code units that are not necessarily null-terminated. | Misc/StringBuilder.h | |
void InsertAt
(
int32 Pos, |
Insert substring at given position | Misc/StringBuilder.h | |
BuilderType & Join
(
RangeType&& InRange, |
Append every element of the range to the builder, separating the elements by the delimiter. | Misc/StringBuilder.h | |
BuilderType & JoinQuoted
(
RangeType&& InRange, |
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. | Misc/StringBuilder.h | |
CharType LastChar() |
Returns the last character, technically the last code unit. | Misc/StringBuilder.h | |
int32 Len() |
Misc/StringBuilder.h | ||
void Prepend
(
ViewType Str |
Insert prefix | Misc/StringBuilder.h | |
void RemoveAt
(
int32 Pos, |
Remove characters at given position | Misc/StringBuilder.h | |
void RemoveSuffix
(
int32 InCount |
Modifies the string builder to remove the given number of characters from the end. | Misc/StringBuilder.h | |
void ReplaceAt
(
int32 Pos, |
Replace characters at given position and length with substring | Misc/StringBuilder.h | |
void Reserve
(
int32 InNewCapacity |
Reserves memory such that the string builder can contain at least the given number of characters. | Misc/StringBuilder.h | |
void Reset() |
Empties the string builder, but doesn't change memory allocation. | Misc/StringBuilder.h | |
const CharType * ToString () |
Prefer operator*() for a pointer to a null-terminated string. | Misc/StringBuilder.h | |
const CharType * ToString () |
Prefer operator*() for a pointer to a null-terminated string. | Misc/StringBuilder.h | |
ViewType ToView() |
Returns a view of the string that is valid until the builder is mutated. | Misc/StringBuilder.h |
Protected
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
void * AllocBuffer
(
SIZE_T CharCount |
Misc/StringBuilder.h | ||
void EnsureAdditionalCapacity
(
int32 RequiredAdditionalCapacity |
Misc/StringBuilder.h | ||
void EnsureNulTerminated() |
Misc/StringBuilder.h | ||
void Extend
(
SIZE_T ExtraCapacity |
Misc/StringBuilder.h | ||
void FreeBuffer
(
void* Buffer |
Misc/StringBuilder.h | ||
void Initialize
(
CharType* InBase, |
Misc/StringBuilder.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static BuilderType & AppendfImpl
(
BuilderType& Self, |
Misc/StringBuilder.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
const CharType * operator* () |
Returns a pointer to a null-terminated string that is valid until the builder is mutated. | Misc/StringBuilder.h | |
const CharType * operator* () |
Returns a pointer to a null-terminated string that is valid until the builder is mutated. | Misc/StringBuilder.h | |
TStringBuilderBase & operator=
(
const CharType* Str |
Misc/StringBuilder.h | ||
TStringBuilderBase & operator=
(
ViewType Str |
Misc/StringBuilder.h | ||
| Misc/StringBuilder.h | |||
TStringBuilderBase & operator=
(
const TStringBuilderBase& |
Misc/StringBuilder.h |