Ark Server API (ASA) - Wiki
|
#include "CoreTypes.h"
#include "Misc/AssertionMacros.h"
#include "Containers/ContainerAllocationPolicies.h"
#include "Containers/Array.h"
#include "Misc/CString.h"
#include "Templates/AndOrNot.h"
#include "Templates/EnableIf.h"
#include "Templates/IsArray.h"
#include "Templates/RemoveCV.h"
#include "Templates/RemoveReference.h"
#include "Templates/UnrealTemplate.h"
#include "Templates/UnrealTypeTraits.h"
#include "Traits/ElementType.h"
#include "Traits/IsCharEncodingCompatibleWith.h"
#include "Traits/IsContiguousContainer.h"
#include <type_traits>
Go to the source code of this file.
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_Convert > | FTCHARToUTF8 |
typedef TStringConversion< FUTF8ToTCHAR_Convert > | FUTF8ToTCHAR |
typedef TStringPointer< TCHAR, UTF16CHAR > | FTCHARToUTF16 |
typedef TStringPointer< UTF16CHAR, TCHAR > | FUTF16ToTCHAR |
typedef TStringConversion< TUTF16ToUTF32_Convert< TCHAR, UTF32CHAR > > | FTCHARToUTF32 |
typedef TStringConversion< TUTF32ToUTF16_Convert< UTF32CHAR, TCHAR > > | FUTF32ToTCHAR |
typedef TStringPointer< TCHAR, wchar_t > | FTCHARToWChar |
typedef TStringPointer< wchar_t, TCHAR > | FWCharToTCHAR |
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) |
#define ANSI_TO_TCHAR | ( | str | ) | (TCHAR*)StringCast<TCHAR>(static_cast<const ANSICHAR*>(str)).Get() |
Definition at line 961 of file StringConv.h.
#define DEFAULT_STRING_CONVERSION_SIZE 128u |
Definition at line 25 of file StringConv.h.
#define TCHAR_TO_ANSI | ( | str | ) | (ANSICHAR*)StringCast<ANSICHAR>(static_cast<const TCHAR*>(str)).Get() |
Definition at line 960 of file StringConv.h.
#define TCHAR_TO_UTF16 | ( | str | ) | (UTF16CHAR*)(str) |
Definition at line 996 of file StringConv.h.
#define TCHAR_TO_UTF32 | ( | str | ) | (UTF32CHAR*)FTCHARToUTF32((const TCHAR*)str).Get() |
Definition at line 1001 of file StringConv.h.
#define TCHAR_TO_UTF8 | ( | str | ) | (ANSICHAR*)FTCHARToUTF8((const TCHAR*)str).Get() |
Definition at line 962 of file StringConv.h.
#define TCHAR_TO_WCHAR | ( | str | ) | (wchar_t*)(str) |
Definition at line 1025 of file StringConv.h.
#define UTF16_TO_TCHAR | ( | str | ) | (TCHAR*)(str) |
Definition at line 997 of file StringConv.h.
#define UTF32_TO_TCHAR | ( | str | ) | (TCHAR*)FUTF32ToTCHAR((const UTF32CHAR*)str).Get() |
Definition at line 1002 of file StringConv.h.
#define UTF8_TO_TCHAR | ( | str | ) | (TCHAR*)FUTF8ToTCHAR((const ANSICHAR*)str).Get() |
Definition at line 963 of file StringConv.h.
#define WCHAR_TO_TCHAR | ( | str | ) | (TCHAR*)(str) |
Definition at line 1026 of file StringConv.h.
typedef TStringPointer<TCHAR, UTF16CHAR> FTCHARToUTF16 |
Definition at line 994 of file StringConv.h.
Definition at line 999 of file StringConv.h.
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.
typedef TStringPointer<TCHAR, wchar_t> FTCHARToWChar |
Definition at line 1023 of file StringConv.h.
typedef TStringPointer<UTF16CHAR, TCHAR> FUTF16ToTCHAR |
Definition at line 995 of file StringConv.h.
Definition at line 1000 of file StringConv.h.
Definition at line 957 of file StringConv.h.
typedef TStringPointer<wchar_t, TCHAR> FWCharToTCHAR |
Definition at line 1024 of file StringConv.h.
FORCEINLINE To CharCast | ( | From | Ch | ) |
Casts one fixed-width char type into another.
Ch | The character to convert. |
Definition at line 1093 of file StringConv.h.
|
inline |
Definition at line 778 of file StringConv.h.
|
inline |
Definition at line 914 of file StringConv.h.
|
inline |
Definition at line 784 of file StringConv.h.
|
inline |
Definition at line 920 of file StringConv.h.
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.
Str | The null-terminated source string to convert. |
Definition at line 1054 of file StringConv.h.
FORCEINLINE auto StringCast | ( | const From * | Str, |
int32 | Len ) |
Creates an object which acts as a source of a given string type. See example above.
Str | The source string to convert, not necessarily null-terminated. |
Len | The number of From elements in Str. |
Definition at line 1073 of file StringConv.h.
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.
FORCEINLINE TArray< ToType > StringToArray | ( | const FromType * | Src, |
int32 | SrcLen ) |
Definition at line 1216 of file StringConv.h.
FORCEINLINE TArray< ToType > StringToArray | ( | const FromType * | Str | ) |
Definition at line 1228 of file StringConv.h.