engine
 
载入中...
搜索中...
未找到
Public 成员函数 | 所有成员列表
TStringView< CharType > 模板类 参考

String View 更多...

#include <StringView.h>

Public 成员函数

constexpr const CharType * begin () const
 DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support.
 
CORE_API int32 Compare (ViewType Other, ESearchCase::Type SearchCase=ESearchCase::CaseSensitive) const
 Compare this view lexicographically with another view. 更多...
 
SizeType CopyString (CharType *Dest, SizeType CharCount, SizeType Position=0) const
 Copy characters from the view into a destination buffer without null termination. 更多...
 
constexpr const CharType * Data () const
 Returns a pointer to the start of the view. 更多...
 
bool EndsWith (CharType Suffix) const
 Returns whether this view ends with the suffix character compared case-sensitively.
 
bool EndsWith (ViewType Suffix, ESearchCase::Type SearchCase=ESearchCase::IgnoreCase) const
 Returns whether this view ends with the suffix with optional case sensitivity.
 
bool Equals (ViewType Other, ESearchCase::Type SearchCase=ESearchCase::CaseSensitive) const
 Check whether this view is lexicographically equivalent to another view. 更多...
 
CORE_API bool FindChar (CharType InChar, SizeType &OutIndex) const
 Search the view for the first occurrence of a character. 更多...
 
CORE_API bool FindLastChar (CharType InChar, SizeType &OutIndex) const
 Search the view for the last occurrence of a character. 更多...
 
constexpr const CharType * GetData () const
 Returns a pointer to the start of the view. 更多...
 
constexpr bool IsEmpty () const
 Returns whether the string view is empty.
 
ViewType Left (SizeType CharCount) const
 Returns the left-most part of the view by taking the given number of characters from the left.
 
ViewType LeftChop (SizeType CharCount) const
 Returns the left-most part of the view by chopping the given number of characters from the right.
 
void LeftChopInline (SizeType CharCount)
 Modifies the view by chopping the given number of characters from the right.
 
void LeftInline (SizeType CharCount)
 Modifies the view to be the given number of characters from the left.
 
constexpr SizeType Len () const
 Returns the length of the string view.
 
ViewType Mid (SizeType Position, SizeType CharCount=TNumericLimits< SizeType >::Max()) const
 Returns the middle part of the view by taking up to the given number of characters from the given position.
 
void MidInline (SizeType Position, SizeType CharCount=TNumericLimits< SizeType >::Max())
 Modifies the view to be the middle part by taking up to the given number of characters from the given position.
 
const CharType & operator[] (SizeType Index) const
 Access the character at the given index in the view.
 
void RemovePrefix (SizeType CharCount)
 Modifies the view to remove the given number of characters from the start.
 
void RemoveSuffix (SizeType CharCount)
 Modifies the view to remove the given number of characters from the end.
 
void Reset ()
 Resets to an empty view
 
ViewType Right (SizeType CharCount) const
 Returns the right-most part of the view by taking the given number of characters from the right.
 
ViewType RightChop (SizeType CharCount) const
 Returns the right-most part of the view by chopping the given number of characters from the left.
 
void RightChopInline (SizeType CharCount)
 Modifies the view by chopping the given number of characters from the left.
 
void RightInline (SizeType CharCount)
 Modifies the view to be the given number of characters from the right.
 
bool StartsWith (CharType Prefix) const
 Returns whether this view starts with the prefix character compared case-sensitively.
 
bool StartsWith (ViewType Prefix, ESearchCase::Type SearchCase=ESearchCase::IgnoreCase) const
 Returns whether this view starts with the prefix with optional case sensitivity.
 
ViewType SubStr (SizeType Position, SizeType CharCount) const
 Alias for Mid.
 
CORE_API ViewType TrimEnd () const
 Returns the left part of the view before any whitespace at the end.
 
void TrimEndInline ()
 Modifies the view to be the left part before any whitespace at the end.
 
CORE_API ViewType TrimStart () const
 Returns the right part of the view after any whitespace at the start.
 
ViewType TrimStartAndEnd () const
 Returns the middle part of the view between any whitespace at the start and end.
 
void TrimStartAndEndInline ()
 Modifies the view to be the middle part between any whitespace at the start and end.
 
void TrimStartInline ()
 Modifies the view to be the right part after any whitespace at the start.
 
constexpr TStringView ()=default
 Construct an empty view.
 
template<typename CharRangeType , typename TEnableIf< TAnd< TNot< TIsSame< ViewType, typename TDecay< CharRangeType >::Type > >, TIsCharRange< CharRangeType > >::Value >::Type * = nullptr>
constexpr TStringView (CharRangeType &&InRange)
 Construct a view from a contiguous range of characters. 更多...
 
constexpr TStringView (const CharType *InData)
 Construct a view of the null-terminated string pointed to by InData. 更多...
 
constexpr TStringView (const CharType *InData, SizeType InSize)
 Construct a view of InSize characters beginning at InData. 更多...
 

详细描述

template<typename CharType>
class TStringView< CharType >

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.

void DoFoo(FStringView InString);
// DoFoo may be called as:
void MultiFoo()
{
FString MyFoo(TEXT("Zoo"));
const TCHAR* MyFooStr = *MyFoo;
BuiltFoo.Append(TEXT("ABC"));
DoFoo(MyFoo);
DoFoo(MyFooStr);
DoFoo(TEXT("ABC"));
DoFoo(BuiltFoo);
}
A dynamically sizeable string.
Definition: UnrealString.h:43
A string builder with inline storage.
Definition: StringBuilder.h:319
String View
Definition: StringView.h:72

构造及析构函数说明

◆ TStringView() [1/3]

template<typename CharType >
constexpr TStringView< CharType >::TStringView ( const CharType *  InData)
inlineconstexpr

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

The caller is responsible for ensuring that the provided character range remains valid for the lifetime of the view.

◆ TStringView() [2/3]

template<typename CharType >
constexpr TStringView< CharType >::TStringView ( const CharType *  InData,
SizeType  InSize 
)
inlineconstexpr

Construct a view of InSize characters beginning at InData.

The caller is responsible for ensuring that the provided character range remains valid for the lifetime of the view.

◆ TStringView() [3/3]

template<typename CharType >
template<typename CharRangeType , typename TEnableIf< TAnd< TNot< TIsSame< ViewType, typename TDecay< CharRangeType >::Type > >, TIsCharRange< CharRangeType > >::Value >::Type * = nullptr>
constexpr TStringView< CharType >::TStringView ( CharRangeType &&  InRange)
inlineconstexpr

Construct a view from a contiguous range of characters.

The caller is responsible for ensuring that the provided character range remains valid for the lifetime of the view.

成员函数说明

◆ Compare()

template<typename CharType >
CORE_API int32 TStringView< CharType >::Compare ( ViewType  Other,
ESearchCase::Type  SearchCase = ESearchCase::CaseSensitive 
) const

Compare this view lexicographically with another view.

参数
SearchCaseWhether the comparison should ignore case.
返回
0 is equal, negative if this view is less, positive if this view is greater.

◆ CopyString()

template<typename CharType >
SizeType TStringView< CharType >::CopyString ( CharType *  Dest,
SizeType  CharCount,
SizeType  Position = 0 
) const
inline

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

参数
DestBuffer to write into. Must have space for at least CharCount characters.
CharCountThe maximum number of characters to copy.
PositionThe offset into the view from which to start copying.
返回
The number of characters written to the destination buffer.

◆ Data()

template<typename CharType >
constexpr const CharType * TStringView< CharType >::Data ( ) const
inlineconstexpr

Returns a pointer to the start of the view.

This is NOT guaranteed to be null-terminated!

◆ Equals()

template<typename CharType >
bool TStringView< CharType >::Equals ( ViewType  Other,
ESearchCase::Type  SearchCase = ESearchCase::CaseSensitive 
) const
inline

Check whether this view is lexicographically equivalent to another view.

参数
SearchCaseWhether the comparison should ignore case.

◆ FindChar()

template<typename CharType >
CORE_API bool TStringView< CharType >::FindChar ( CharType  InChar,
SizeType &  OutIndex 
) const

Search the view for the first occurrence of a character.

参数
InCharThe character to search for. Comparison is lexicographic.
OutIndex[out] The position at which the character was found, or INDEX_NONE if not found.
返回
Whether the character was found in the view.

◆ FindLastChar()

template<typename CharType >
CORE_API bool TStringView< CharType >::FindLastChar ( CharType  InChar,
SizeType &  OutIndex 
) const

Search the view for the last occurrence of a character.

参数
InCharThe character to search for. Comparison is lexicographic.
OutIndex[out] The position at which the character was found, or INDEX_NONE if not found.
返回
Whether the character was found in the view.

◆ GetData()

template<typename CharType >
constexpr const CharType * TStringView< CharType >::GetData ( ) const
inlineconstexpr

Returns a pointer to the start of the view.

This is NOT guaranteed to be null-terminated!


该类的文档由以下文件生成: