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. 更多... | |
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.
|
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.
|
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.
|
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.
| CORE_API int32 TStringView< CharType >::Compare | ( | ViewType | Other, |
| ESearchCase::Type | SearchCase = ESearchCase::CaseSensitive |
||
| ) | const |
Compare this view lexicographically with another view.
| SearchCase | Whether the comparison should ignore case. |
|
inline |
Copy characters from the view into a destination buffer without null termination.
| Dest | Buffer to write into. Must have space for at least CharCount characters. |
| CharCount | The maximum number of characters to copy. |
| Position | The offset into the view from which to start copying. |
|
inlineconstexpr |
Returns a pointer to the start of the view.
This is NOT guaranteed to be null-terminated!
|
inline |
Check whether this view is lexicographically equivalent to another view.
| SearchCase | Whether the comparison should ignore case. |
| CORE_API bool TStringView< CharType >::FindChar | ( | CharType | InChar, |
| SizeType & | OutIndex | ||
| ) | const |
Search the view for the first occurrence of a character.
| InChar | The character to search for. Comparison is lexicographic. |
| OutIndex | [out] The position at which the character was found, or INDEX_NONE if not found. |
| CORE_API bool TStringView< CharType >::FindLastChar | ( | CharType | InChar, |
| SizeType & | OutIndex | ||
| ) | const |
Search the view for the last occurrence of a character.
| InChar | The character to search for. Comparison is lexicographic. |
| OutIndex | [out] The position at which the character was found, or INDEX_NONE if not found. |
|
inlineconstexpr |
Returns a pointer to the start of the view.
This is NOT guaranteed to be null-terminated!