TStringView

A fixed-size string builder for TCHAR.

Windows
MacOS
Linux

Deprecated

  • 'TFixedAnsiStringBuilder' is deprecated. Please use 'TAnsiStringBuilder' instead!

References

Module

Core

Header

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

Include

#include "Containers/StringFwd.h"

Syntax

template<typename CharType>
class TStringView

Remarks

A fixed-size string builder for TCHAR. A fixed-size string builder for ANSICHAR.

String View

A string view is implicitly constructible from const char* style strings and from compatible character ranges such as FString and TStringBuilderBase.

A string view does not own any data nor does it attempt to control any lifetimes, it merely points at a subrange of characters in some other string. It's up to the user to ensure the underlying string stays valid for the lifetime of the string view.

A string view is cheap to copy and is intended to be passed by value.

A string view does not represent a NUL terminated string and therefore you should never pass in the pointer returned by GetData() into a C-string API accepting only a pointer. You must either use a string builder to make a properly terminated string, or use an API that accepts a length argument in addition to the C-string.

String views are a good fit for arguments to functions which don't wish to care which style of string construction is used by the caller. If you accept strings via string views then the caller is free to use FString, FStringBuilder, raw C strings, or any other type which can be converted into a string view.

The UE::String namespace contains many functions that can operate on string views. Most of these can be found in String/___.h in Core.

voidDoFoo(FStringViewInString);//DoFoomaybecalledas:voidMultiFoo(){FStringMyFoo(TEXT("Zoo"));constTCHAR*MyFooStr=*MyFoo;TStringBuilder<64>BuiltFoo;BuiltFoo.Append(TEXT("ABC"));DoFoo(MyFoo);DoFoo(MyFooStr);DoFoo(TEXT("ABC"));DoFoo(BuiltFoo);}

Variables

Name Description

Protected variable

const CharType ...

 

DataPtr

Protected variable

SizeType

 

Size

Constructors

Name Description

Public function

TStringView()

Construct an empty view.

Public function

TStringView

(
    const CharType* InData
)

Construct a view of the null-terminated string pointed to by InData.

Public function

TStringView

(
    CharRangeType&& InRange
)

Construct a view from a contiguous range of characters.

Public function

TStringView

(
    const CharType* InData,
    SizeType InSize
)

Construct a view of InSize characters beginning at InData.

Functions

Name Description

Public function Const

constexpr co...

 

begin()

DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support.

Public function Const

int32

 

Compare

(
    const OtherCharType* Other,
    ESearchCase::Type SearchCase
)

Compare this view lexicographically with another view.

Public function Const

int32

 

Compare

(
    OtherType&& Other,
    ESearchCase::Type SearchCase
)

Compare this view lexicographically with another view.

Public function Const

SizeType

 

CopyString

(
    CharType* Dest,
    SizeType CharCount,
    SizeType Position
)

Copy characters from the view into a destination buffer without null termination.

Public function Const

constexpr co...

 

end()

Public function Const

bool

 

EndsWith

(
    CharType Suffix
)

Returns whether this view ends with the suffix character compared case-sensitively.

Public function Const

bool

 

EndsWith

(
    ViewType Suffix,
    ESearchCase::Type SearchCase
)

Returns whether this view ends with the suffix with optional case sensitivity.

Public function Const

bool

 

Equals

(
    OtherType&& Other,
    ESearchCase::Type SearchCase
)

Check whether this view is lexicographically equivalent to another view.

Public function Const

bool

 

Equals

(
    const OtherCharType* Other,
    ESearchCase::Type SearchCase
)

Check whether this view is lexicographically equivalent to another view.

Public function Const

bool

 

FindChar

(
    CharType InChar,
    SizeType& OutIndex
)

Search the view for the first occurrence of a character.

Public function Const

bool

 

FindLastChar

(
    CharType InChar,
    SizeType& OutIndex
)

Search the view for the last occurrence of a character.

Public function Const

constexpr co...

 

GetData()

Returns a pointer to the start of the view. This is NOT guaranteed to be null-terminated!

Public function Const

constexpr bo...

 

IsEmpty()

Returns whether the string view is empty.

Public function Const

ViewType

 

Left

(
    SizeType CharCount
)

Returns the left-most part of the view by taking the given number of characters from the left.

Public function Const

ViewType

 

LeftChop

(
    SizeType CharCount
)

Returns the left-most part of the view by chopping the given number of characters from the right.

Public function

void

 

LeftChopInline

(
    SizeType CharCount
)

Modifies the view by chopping the given number of characters from the right.

Public function

void

 

LeftInline

(
    SizeType CharCount
)

Modifies the view to be the given number of characters from the left.

Public function Const

constexpr Si...

 

Len()

Returns the length of the string view.

Public function Const

ViewType

 

Mid

(
    SizeType Position,
    SizeType CharCount
)

Returns the middle part of the view by taking up to the given number of characters from the given position.

Public function

void

 

MidInline

(
    SizeType Position,
    SizeType CharCount
)

Modifies the view to be the middle part by taking up to the given number of characters from the given position.

Public function

void

 

RemovePrefix

(
    SizeType CharCount
)

Modifies the view to remove the given number of characters from the start.

Public function

void

 

RemoveSuffix

(
    SizeType CharCount
)

Modifies the view to remove the given number of characters from the end.

Public function

void

 

Reset()

Resets to an empty view

Public function Const

ViewType

 

Right

(
    SizeType CharCount
)

Returns the right-most part of the view by taking the given number of characters from the right.

Public function Const

ViewType

 

RightChop

(
    SizeType CharCount
)

Returns the right-most part of the view by chopping the given number of characters from the left.

Public function

void

 

RightChopInline

(
    SizeType CharCount
)

Modifies the view by chopping the given number of characters from the left.

Public function

void

 

RightInline

(
    SizeType CharCount
)

Modifies the view to be the given number of characters from the right.

Public function Const

bool

 

StartsWith

(
    CharType Prefix
)

Returns whether this view starts with the prefix character compared case-sensitively.

Public function Const

bool

 

StartsWith

(
    ViewType Prefix,
    ESearchCase::Type SearchCase
)

Returns whether this view starts with the prefix with optional case sensitivity.

Public function Const

ViewType

 

SubStr

(
    SizeType Position,
    SizeType CharCount
)

Alias for Mid.

Public function Const

ViewType

 

TrimEnd()

Returns the left part of the view before any whitespace at the end.

Public function

void

 

TrimEndInline()

Modifies the view to be the left part before any whitespace at the end.

Public function Const

ViewType

 

TrimStart()

Returns the right part of the view after any whitespace at the start.

Public function Const

ViewType

 

TrimStartAndEnd()

Returns the middle part of the view between any whitespace at the start and end.

Public function

void

 

TrimStartAndEndInline()

Modifies the view to be the middle part between any whitespace at the start and end.

Public function

void

 

TrimStartInline()

Modifies the view to be the right part after any whitespace at the start.

Operators

Name Description

Public function Const

const CharTy...

 

operator[]

(
    SizeType Index
)

Access the character at the given index in the view.

Typedefs

Name

Description

ElementType

SizeType

TIsCharRange

Trait testing whether a type is a contiguous range of CharType, and not CharType[].

ViewType

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss