Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
StringConv.h File Reference
+ Include dependency graph for StringConv.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  TStringConvert< From, To >
 
struct  UE::Core::Private::FCountingOutputIterator
 
class  UE::Core::Private::FTCHARToUTF8_Convert
 
class  FUTF8ToTCHAR_Convert
 
class  TUTF32ToUTF16_Convert< InFromType, InToType >
 
class  TUTF16ToUTF32_Convert< InFromType, InToType >
 
struct  ENullTerminatedString
 
class  TStringConversion< Converter, DefaultConversionSize >
 
struct  TIsContiguousContainer< TStringConversion< Converter, DefaultConversionSize > >
 
struct  TElementType< TStringConversion< Converter, DefaultConversionSize > >
 
class  TStringPointer< InFromType, InToType >
 
struct  TIsContiguousContainer< TStringPointer< FromType, ToType > >
 
struct  TElementType< TStringPointer< FromType, ToType > >
 
class  TStringPassthru< ToType, FromType, DefaultConversionSize >
 
class  TPassthruPointer< T >
 

Namespaces

namespace  StringConv
 
namespace  UE
 
namespace  UE::Core
 
namespace  UE::Core::Private
 

Macros

#define DEFAULT_STRING_CONVERSION_SIZE   128u
 
#define TCHAR_TO_ANSI(str)   (ANSICHAR*)StringCast<ANSICHAR>(static_cast<const TCHAR*>(str)).Get()
 
#define ANSI_TO_TCHAR(str)   (TCHAR*)StringCast<TCHAR>(static_cast<const ANSICHAR*>(str)).Get()
 
#define TCHAR_TO_UTF8(str)   (ANSICHAR*)FTCHARToUTF8((const TCHAR*)str).Get()
 
#define UTF8_TO_TCHAR(str)   (TCHAR*)FUTF8ToTCHAR((const ANSICHAR*)str).Get()
 
#define TCHAR_TO_UTF16(str)   (UTF16CHAR*)(str)
 
#define UTF16_TO_TCHAR(str)   (TCHAR*)(str)
 
#define TCHAR_TO_UTF32(str)   (UTF32CHAR*)FTCHARToUTF32((const TCHAR*)str).Get()
 
#define UTF32_TO_TCHAR(str)   (TCHAR*)FUTF32ToTCHAR((const UTF32CHAR*)str).Get()
 
#define TCHAR_TO_WCHAR(str)   (wchar_t*)(str)
 
#define WCHAR_TO_TCHAR(str)   (TCHAR*)(str)
 

Typedefs

typedef TStringConversion< UE::Core::Private::FTCHARToUTF8_ConvertFTCHARToUTF8
 
typedef TStringConversion< FUTF8ToTCHAR_ConvertFUTF8ToTCHAR
 
typedef TStringPointer< TCHAR, UTF16CHARFTCHARToUTF16
 
typedef TStringPointer< UTF16CHAR, TCHARFUTF16ToTCHAR
 
typedef TStringConversion< TUTF16ToUTF32_Convert< TCHAR, UTF32CHAR > > FTCHARToUTF32
 
typedef TStringConversion< TUTF32ToUTF16_Convert< UTF32CHAR, TCHAR > > FUTF32ToTCHAR
 
typedef TStringPointer< TCHAR, wchar_t > FTCHARToWChar
 
typedef TStringPointer< wchar_t, TCHARFWCharToTCHAR
 

Functions

FORCEINLINE bool StringConv::IsValidCodepoint (const uint32 Codepoint)
 
FORCEINLINE bool StringConv::IsHighSurrogate (const uint32 Codepoint)
 
FORCEINLINE bool StringConv::IsLowSurrogate (const uint32 Codepoint)
 
FORCEINLINE uint32 StringConv::EncodeSurrogate (const uint16 HighSurrogate, const uint16 LowSurrogate)
 
FORCEINLINE void StringConv::DecodeSurrogate (const uint32 Codepoint, uint16 &OutHighSurrogate, uint16 &OutLowSurrogate)
 
FORCEINLINE bool StringConv::IsEncodedSurrogate (const uint32 Codepoint)
 
template<typename CharType >
FORCEINLINE int32 StringConv::InlineCombineSurrogates_Buffer (CharType *StrBuffer, int32 StrLen)
 
template<typename AllocatorType >
FORCEINLINE void StringConv::InlineCombineSurrogates_Array (TArray< TCHAR, AllocatorType > &StrBuffer)
 
template<typename ConverterType >
ConverterType::LegacyFromType StringConv::GetLegacyFromType (typename ConverterType::LegacyFromType *)
 
template<typename ConverterType >
FUnused StringConv::GetLegacyFromType (...)
 
template<typename Converter , int32 DefaultConversionSize>
auto GetData (const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Get())
 
template<typename Converter , int32 DefaultConversionSize>
auto GetNum (const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Length())
 
template<typename FromType , typename ToType >
auto GetData (const TStringPointer< FromType, ToType > &Pointer) -> decltype(Pointer.Get())
 
template<typename FromType , typename ToType >
auto GetNum (const TStringPointer< FromType, ToType > &Pointer) -> decltype(Pointer.Length())
 
template<typename To , int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE, typename From >
FORCEINLINE auto StringCast (const From *Str)
 
template<typename To , int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE, typename From >
FORCEINLINE auto StringCast (const From *Str, int32 Len)
 
template<typename To , typename From >
FORCEINLINE To CharCast (From Ch)
 
template<typename From , typename To , int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE>
FORCEINLINE auto StringMemoryPassthru (To *Buffer, int32 BufferSize, int32 SourceLength)
 
template<typename ToType , typename FromType >
FORCEINLINE TArray< ToType > StringToArray (const FromType *Src, int32 SrcLen)
 
template<typename ToType , typename FromType >
FORCEINLINE TArray< ToType > StringToArray (const FromType *Str)
 

Macro Definition Documentation

◆ ANSI_TO_TCHAR

#define ANSI_TO_TCHAR ( str)    (TCHAR*)StringCast<TCHAR>(static_cast<const ANSICHAR*>(str)).Get()

Definition at line 961 of file StringConv.h.

◆ DEFAULT_STRING_CONVERSION_SIZE

#define DEFAULT_STRING_CONVERSION_SIZE   128u

Definition at line 25 of file StringConv.h.

◆ TCHAR_TO_ANSI

#define TCHAR_TO_ANSI ( str)    (ANSICHAR*)StringCast<ANSICHAR>(static_cast<const TCHAR*>(str)).Get()

Definition at line 960 of file StringConv.h.

◆ TCHAR_TO_UTF16

#define TCHAR_TO_UTF16 ( str)    (UTF16CHAR*)(str)

Definition at line 996 of file StringConv.h.

◆ TCHAR_TO_UTF32

#define TCHAR_TO_UTF32 ( str)    (UTF32CHAR*)FTCHARToUTF32((const TCHAR*)str).Get()

Definition at line 1001 of file StringConv.h.

◆ TCHAR_TO_UTF8

#define TCHAR_TO_UTF8 ( str)    (ANSICHAR*)FTCHARToUTF8((const TCHAR*)str).Get()

Definition at line 962 of file StringConv.h.

◆ TCHAR_TO_WCHAR

#define TCHAR_TO_WCHAR ( str)    (wchar_t*)(str)

Definition at line 1025 of file StringConv.h.

◆ UTF16_TO_TCHAR

#define UTF16_TO_TCHAR ( str)    (TCHAR*)(str)

Definition at line 997 of file StringConv.h.

◆ UTF32_TO_TCHAR

#define UTF32_TO_TCHAR ( str)    (TCHAR*)FUTF32ToTCHAR((const UTF32CHAR*)str).Get()

Definition at line 1002 of file StringConv.h.

◆ UTF8_TO_TCHAR

#define UTF8_TO_TCHAR ( str)    (TCHAR*)FUTF8ToTCHAR((const ANSICHAR*)str).Get()

Definition at line 963 of file StringConv.h.

◆ WCHAR_TO_TCHAR

#define WCHAR_TO_TCHAR ( str)    (TCHAR*)(str)

Definition at line 1026 of file StringConv.h.

Typedef Documentation

◆ FTCHARToUTF16

Definition at line 994 of file StringConv.h.

◆ FTCHARToUTF32

◆ FTCHARToUTF8

NOTE: The objects these macros declare have very short lifetimes. They are meant to be used as parameters to functions. You cannot assign a variable to the contents of the converted string as the object will go out of scope and the string released.

NOTE: The parameter you pass in MUST be a proper string, as the parameter is typecast to a pointer. If you pass in a char, not char* it will compile and then crash at runtime.

Usage:

SomeApi(TCHAR_TO_ANSI(SomeUnicodeString));

const char* SomePointer = TCHAR_TO_ANSI(SomeUnicodeString); <--- Bad!!!

Definition at line 956 of file StringConv.h.

◆ FTCHARToWChar

typedef TStringPointer<TCHAR, wchar_t> FTCHARToWChar

Definition at line 1023 of file StringConv.h.

◆ FUTF16ToTCHAR

Definition at line 995 of file StringConv.h.

◆ FUTF32ToTCHAR

◆ FUTF8ToTCHAR

Definition at line 957 of file StringConv.h.

◆ FWCharToTCHAR

typedef TStringPointer<wchar_t, TCHAR> FWCharToTCHAR

Definition at line 1024 of file StringConv.h.

Function Documentation

◆ CharCast()

template<typename To , typename From >
FORCEINLINE To CharCast ( From Ch)

Casts one fixed-width char type into another.

Parameters
ChThe character to convert.
Returns
The converted character.

Definition at line 1093 of file StringConv.h.

◆ GetData() [1/2]

template<typename Converter , int32 DefaultConversionSize>
auto GetData ( const TStringConversion< Converter, DefaultConversionSize > & Conversion) -> decltype(Conversion.Get())
inline

Definition at line 778 of file StringConv.h.

◆ GetData() [2/2]

template<typename FromType , typename ToType >
auto GetData ( const TStringPointer< FromType, ToType > & Pointer) -> decltype(Pointer.Get())
inline

Definition at line 914 of file StringConv.h.

◆ GetNum() [1/2]

template<typename Converter , int32 DefaultConversionSize>
auto GetNum ( const TStringConversion< Converter, DefaultConversionSize > & Conversion) -> decltype(Conversion.Length())
inline

Definition at line 784 of file StringConv.h.

◆ GetNum() [2/2]

template<typename FromType , typename ToType >
auto GetNum ( const TStringPointer< FromType, ToType > & Pointer) -> decltype(Pointer.Length())
inline

Definition at line 920 of file StringConv.h.

◆ StringCast() [1/2]

template<typename To , int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE, typename From >
FORCEINLINE auto StringCast ( const From * Str)

StringCast example usage:

void Func(const FString& Str, const TCHAR* MediumLong, FStringView MediumLongSV) { // Basic version auto Src = StringCast<ANSICHAR>(<em>Str); const ANSICHAR Ptr = Src.Get(); // Ptr is a pointer to an ANSICHAR representing the potentially-converted string data. // Avoid calling strlen auto NoStrlenString = StringCast<ANSICHAR>(MediumLongSV.GetData(), MediumLongSV.Len()); // Specify the static allocation size when maximum length is known auto NoAllocSrc = StringCast<ANSICHAR, 1024>(MediumLong); // Avoid calling strlen and also specify the allocation size auto NoAllocNoStrlenSrc = StringCast<ANSICHAR, 1024>(MediumLongSV.GetData(), MediumLongSV.Len()); } Creates an object which acts as a source of a given string type. See example above.

Parameters
StrThe null-terminated source string to convert.

Definition at line 1054 of file StringConv.h.

◆ StringCast() [2/2]

template<typename To , int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE, typename From >
FORCEINLINE auto StringCast ( const From * Str,
int32 Len )

Creates an object which acts as a source of a given string type. See example above.

Parameters
StrThe source string to convert, not necessarily null-terminated.
LenThe number of From elements in Str.

Definition at line 1073 of file StringConv.h.

◆ StringMemoryPassthru()

template<typename From , typename To , int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE>
FORCEINLINE auto StringMemoryPassthru ( To * Buffer,
int32 BufferSize,
int32 SourceLength )

Allows the efficient conversion of strings by means of a temporary memory buffer only when necessary. Intended to be used when you have an API which populates a buffer with some string representation which is ultimately going to be stored in another representation, but where you don't want to do a conversion or create a temporary buffer for that string if it's not necessary.

Intended use:

// Populates the buffer Str with StrLen characters. void SomeAPI(APICharType* Str, int32 StrLen);

void Func(DestChar* Buffer, int32 BufferSize) { // Create a passthru. This takes the buffer (and its size) which will ultimately hold the string, as well as the length of the // string that's being converted, which must be known in advance. // An explicit template argument is also passed to indicate the character type of the source string. // Buffer must be correctly typed for the destination string type. auto Passthru = StringMemoryPassthru<APICharType>(Buffer, BufferSize, SourceLength);

// Passthru.Get() returns an APICharType buffer pointer which is guaranteed to be SourceLength characters in size. // It's possible, and in fact intended, for Get() to return the same pointer as Buffer if DestChar and APICharType are // compatible string types. If this is the case, SomeAPI will write directly into Buffer. If the string types are not // compatible, Get() will return a pointer to some temporary memory which allocated by and owned by the passthru. SomeAPI(Passthru.Get(), SourceLength);

// If the string types were not compatible, then the passthru used temporary storage, and we need to write that back to Buffer. // We do that with the Apply call. If the string types were compatible, then the data was already written to Buffer directly // and so Apply is a no-op. Passthru.Apply();

// Now Buffer holds the data output by SomeAPI, already converted if necessary. }

Definition at line 1202 of file StringConv.h.

◆ StringToArray() [1/2]

template<typename ToType , typename FromType >
FORCEINLINE TArray< ToType > StringToArray ( const FromType * Src,
int32 SrcLen )

Definition at line 1216 of file StringConv.h.

◆ StringToArray() [2/2]

template<typename ToType , typename FromType >
FORCEINLINE TArray< ToType > StringToArray ( const FromType * Str)

Definition at line 1228 of file StringConv.h.