11#include "Containers/Array.h"
21#define DEFAULT_STRING_CONVERSION_SIZE 128u
23template <
typename From,
typename To>
34 inline static void Convert(To* Dest,
int32 DestLen,
const CharType* Source,
int32 SourceLen)
36 To* Result = FPlatformString::Convert(Dest, DestLen, (
const FromType*)Source, SourceLen);
46 return FPlatformString::ConvertedLength<To>((
const FromType*)Source, SourceLen);
55 if ((Codepoint > 0x10FFFF) ||
56 (Codepoint == 0xFFFE) || (Codepoint == 0xFFFF))
94 template<
typename CharType>
97 static_assert(
sizeof(CharType) == 4,
"CharType must be 4-bytes!");
107 if ((
Index + 1) >= StrLen)
127 const int32 ArrayNum = StrLen + 1;
153 template<
typename AllocatorType>
156#if PLATFORM_TCHAR_IS_4_BYTES
165 template <
typename ConverterType>
166 typename ConverterType::LegacyFromType
GetLegacyFromType(
typename ConverterType::LegacyFromType*);
168 template <
typename ConverterType>
205 template <
typename T>
213 return Lhs.Counter - Rhs.Counter;
243 template <
typename BufferType>
264 if (Codepoint < 0x80)
268 else if (Codepoint < 0x800)
276 else if (Codepoint < 0x10000)
315 IntendedToType* Result = FPlatformString::Convert(Dest, DestLen, (
const FromType*)Source, SourceLen);
321 return (
int32)(Result - Dest);
344 return FPlatformString::ConvertedLength<IntendedToType>((
const FromType*)Source, SourceLen);
385 FPlatformString::Convert(Dest, DestLen, (
const FromType*)Source, SourceLen);
389 FPlatformString::Convert(Dest, DestLen, (
const FromType*)Source, SourceLen);
405 return FPlatformString::ConvertedLength<ToType>((
const FromType*)Source, SourceLen);
409 return FPlatformString::ConvertedLength<ToType>((
const FromType*)Source, SourceLen);
413template<
typename InFromType,
typename InToType>
416 static_assert(
sizeof(
InFromType) == 4,
"FromType must be 4 bytes!");
417 static_assert(
sizeof(
InToType) == 2,
"ToType must be 2 bytes!");
431 template <
typename BufferType>
493 Convert_Impl(Dest, DestLen, (
const FromType*)Source, SourceLen);
508 const int32 DestLen = SourceLen * 2;
509 Convert_Impl(Dest, DestLen, (
const FromType*)Source, SourceLen);
515 template <
typename DestBufferType>
518 for (
int32 i = 0; i < SourceLen; ++i)
522 if (!WriteCodepointToBuffer(Codepoint, Dest, DestLen))
530 template <
typename DestBufferType>
545template<
typename InFromType,
typename InToType>
548 static_assert(
sizeof(
InFromType) == 2,
"FromType must be 2 bytes!");
549 static_assert(
sizeof(
InToType) == 4,
"ToType must be 4 bytes!");
569 Convert_Impl(Dest, DestLen, (
const FromType*)Source, SourceLen);
648 template <
typename DestBufferType>
669template<
typename Converter,
int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE>
674 typedef typename Converter::FromType FromType;
675 typedef typename Converter::ToType ToType;
677 using LegacyFromType =
decltype(StringConv::GetLegacyFromType<Converter>(
nullptr));
686 StringLength = Converter::ConvertedLength(Source, SourceLen);
690 AllocatorType::ResizeAllocation(0, BufferSize,
sizeof(ToType));
692 Ptr = (ToType*)AllocatorType::GetAllocation();
693 Converter::Convert(Ptr, BufferSize, Source, SourceLen +
NullOffset);
733 if (SourceLen > 0 && ((
const FromType*)Source)[SourceLen-1] == 0)
763 typename FromRangeCharType = std::remove_cv_t<std::remove_pointer_t<decltype(GetData(std::declval<FromRangeType>()))>>
801template <
typename Converter,
int32 DefaultConversionSize>
804 return Conversion.Get();
807template <
typename Converter,
int32 DefaultConversionSize>
810 return Conversion.Length();
813template <
typename Converter,
int32 DefaultConversionSize>
819template <
typename Converter,
int32 DefaultConversionSize>
822 using Type =
typename Converter::ToType;
830template<
typename InFromType,
typename InToType = InFromType>
833 static_assert(
sizeof(
InFromType) ==
sizeof(
InToType),
"FromType must be the same size as ToType!");
848 Ptr = (
const ToType*)Source;
866 if (SourceLen > 0 && ((
const FromType*)Source)[SourceLen-1] == 0)
872 Ptr = (
const ToType*)Source;
873 StringLength = SourceLen;
884 : Ptr((const
ToType*)Source)
885 , StringLength(SourceLen)
894 typename FromRangeCharType = std::remove_cv_t<std::remove_pointer_t<decltype(GetData(std::declval<FromRangeType>()))>>
942template <
typename FromType,
typename ToType>
945 return Pointer.Get();
948template <
typename FromType,
typename ToType>
951 return Pointer.Length();
954template <
typename FromType,
typename ToType>
960template <
typename FromType,
typename ToType>
1019#define TCHAR_TO_ANSI(str) (ANSICHAR*)StringCast<ANSICHAR>(static_cast<const TCHAR*>(str)).Get()
1020#define ANSI_TO_TCHAR(str) (TCHAR*)StringCast<TCHAR>(static_cast<const ANSICHAR*>(str)).Get()
1021#define TCHAR_TO_UTF8(str) (ANSICHAR*)FTCHARToUTF8((const TCHAR*)str).Get()
1022#define UTF8_TO_TCHAR(str) (TCHAR*)FUTF8ToTCHAR((const ANSICHAR*)str).Get()
1033#if PLATFORM_TCHAR_IS_4_BYTES
1037#define TCHAR_TO_UTF16(str) (UTF16CHAR*)FTCHARToUTF16((const TCHAR*)str).Get()
1038#define UTF16_TO_TCHAR(str) (TCHAR*)FUTF16ToTCHAR((const UTF16CHAR*)str).Get()
1040static_assert(
sizeof(
TCHAR) ==
sizeof(
UTF32CHAR),
"TCHAR and UTF32CHAR are expected to be the same size for inline conversion! PLATFORM_TCHAR_IS_4_BYTES is not configured correctly for this platform.");
1043#define TCHAR_TO_UTF32(str) (UTF32CHAR*)(str)
1044#define UTF32_TO_TCHAR(str) (TCHAR*)(str)
1046#elif PLATFORM_TCHAR_IS_UTF8CHAR
1050#define TCHAR_TO_UTF16(str) (UTF16CHAR*)FTCHARToUTF16((const TCHAR*)str).Get()
1051#define UTF16_TO_TCHAR(str) (TCHAR*)FUTF16ToTCHAR((const UTF16CHAR*)str).Get()
1055#define TCHAR_TO_UTF32(str) (UTF32CHAR*)FTCHARToUTF32((const TCHAR*)str).Get()
1056#define UTF32_TO_TCHAR(str) (TCHAR*)FUTF32ToTCHAR((const UTF32CHAR*)str).Get()
1060static_assert(
sizeof(
TCHAR) ==
sizeof(
UTF16CHAR),
"TCHAR and UTF16CHAR are expected to be the same size for inline conversion! PLATFORM_TCHAR_IS_4_BYTES is not configured correctly for this platform.");
1063#define TCHAR_TO_UTF16(str) (UTF16CHAR*)(str)
1064#define UTF16_TO_TCHAR(str) (TCHAR*)(str)
1068#define TCHAR_TO_UTF32(str) (UTF32CHAR*)FTCHARToUTF32((const TCHAR*)str).Get()
1069#define UTF32_TO_TCHAR(str) (TCHAR*)FUTF32ToTCHAR((const UTF32CHAR*)str).Get()
1074#if PLATFORM_TCHAR_IS_CHAR16 && PLATFORM_WCHAR_IS_4_BYTES
1077#define TCHAR_TO_WCHAR(str) (wchar_t*)FTCHARToWChar((const TCHAR*)str).Get()
1078#define WCHAR_TO_TCHAR(str) (TCHAR*)FWCharToTCHAR((const wchar_t*)str).Get()
1080#elif PLATFORM_TCHAR_IS_UTF8CHAR
1084#define TCHAR_TO_WCHAR(str) (wchar_t*)FTCHARToUTF32((const TCHAR*)str).Get()
1085#define WCHAR_TO_TCHAR(str) (TCHAR*)FWCharToTCHAR((const wchar_t*)str).Get()
1089static_assert(
sizeof(
TCHAR) ==
sizeof(
wchar_t),
"TCHAR and wchar_t are expected to be the same size for inline conversion! PLATFORM_WCHAR_IS_4_BYTES is not configured correctly for this platform.");
1092#define TCHAR_TO_WCHAR(str) (wchar_t*)(str)
1093#define WCHAR_TO_TCHAR(str) (TCHAR*)(str)
1135template <
typename To,
int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE,
typename From>
1169template <
typename To,
int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE,
typename From>
1206template <
typename To,
int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE,
typename From>
1226template <
typename To,
typename From>
1230 FPlatformString::Convert(&Result, 1, &
Ch, 1);
1237template <
typename ToType,
typename FromType,
int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE>
1248 AllocatorType::ResizeAllocation(0, SrcLen,
sizeof(FromType));
1253 AllocatorType::MoveToEmpty(
Other);
1258 const FromType* Source = (
const FromType*)AllocatorType::GetAllocation();
1259 check(FPlatformString::ConvertedLength<ToType>(Source, SrcLen) <= DestLen);
1260 FPlatformString::Convert(Dest, DestLen, Source, SrcLen);
1265 return (FromType*)AllocatorType::GetAllocation();
1280template <
typename T>
1335template <
typename From,
typename To,
int32 DefaultConversionSize = DEFAULT_STRING_CONVERSION_SIZE>
1340 check(SourceLength <= BufferSize);
1349template <
typename ToType,
typename FromType>
1352 int32 DestLen = FPlatformString::ConvertedLength<ToType>(Src, SrcLen);
1355 Result.AddUninitialized(DestLen);
1356 FPlatformString::Convert(Result.GetData(), DestLen, Src, SrcLen);
1361template <
typename ToType,
typename FromType>
1367#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_4
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
#define UE_PTRDIFF_TO_INT32(argument)
Definition CoreMiscDefines.h:442
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void Init()
Definition LockFreeList.h:4
#define MAX_int32
Definition NumericLimits.h:25
#define UE_REQUIRES(...)
Definition Requires.h:86
auto StringCast(const From *Str)
Definition StringConv.h:1136
TStringConversion< TUTF16ToUTF32_Convert< TCHAR, UTF32CHAR > > FTCHARToUTF32
Definition StringConv.h:1066
TStringPointer< wchar_t, TCHAR > FWCharToTCHAR
Definition StringConv.h:1091
auto GetNum(const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Length())
Definition StringConv.h:808
auto GetData(const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Get())
Definition StringConv.h:802
TStringConversion< TUTF32ToUTF16_Convert< UTF32CHAR, TCHAR > > FUTF32ToTCHAR
Definition StringConv.h:1067
TStringPointer< UTF16CHAR, TCHAR > FUTF16ToTCHAR
Definition StringConv.h:1062
TStringPointer< TCHAR, wchar_t > FTCHARToWChar
Definition StringConv.h:1090
TArray< ToType > StringToArray(const FromType *Src, int32 SrcLen)
Definition StringConv.h:1350
auto StringMemoryPassthru(To *Buffer, int32 BufferSize, int32 SourceLength)
Definition StringConv.h:1336
TStringPointer< TCHAR, UTF16CHAR > FTCHARToUTF16
Definition StringConv.h:1061
auto StrCast(const From *Str, int32 Len)
Definition StringConv.h:1207
To CharCast(From Ch)
Definition StringConv.h:1227
float Val(const FString &Value)
Definition UnrealMath.cpp:3163
Definition StringConv.h:365
UTF8CHAR FromType
Definition StringConv.h:368
static UE_FORCEINLINE_HINT void Convert(ToType *Dest, const int32 DestLen, const SrcBufferType *Source, const int32 SourceLen)
Definition StringConv.h:383
ANSICHAR LegacyFromType
Definition StringConv.h:367
TCHAR ToType
Definition StringConv.h:369
static int32 ConvertedLength(const SrcBufferType *Source, const int32 SourceLen)
Definition StringConv.h:403
static UE_FORCEINLINE_HINT void Convert(ToType *Dest, const int32 DestLen, const LegacyFromType *Source, const int32 SourceLen)
Definition StringConv.h:387
static int32 ConvertedLength(const LegacyFromType *Source, const int32 SourceLen)
Definition StringConv.h:407
Definition StringConv.h:1282
UE_FORCEINLINE_HINT T * Get() const UE_LIFETIMEBOUND
Definition StringConv.h:1290
UE_FORCEINLINE_HINT void Apply() const
Definition StringConv.h:1295
UE_FORCEINLINE_HINT TPassthruPointer(T *InPtr)
Definition StringConv.h:1284
Definition ContainerAllocationPolicies.h:894
Definition StringConv.h:671
TStringConversion & operator=(TStringConversion &&)=delete
UE_FORCEINLINE_HINT const ToType * Get() const UE_LIFETIMEBOUND
Definition StringConv.h:781
TStringConversion(FromRangeType &&Source)
Definition StringConv.h:770
UE_FORCEINLINE_HINT int32 Length() const
Definition StringConv.h:791
TStringConversion(const TStringConversion &)=delete
TStringConversion(TStringConversion &&)=delete
TStringConversion(const LegacyFromType *Source, int32 SourceLen)
Definition StringConv.h:748
TStringConversion(const SrcBufferType *Source, int32 SourceLen)
Definition StringConv.h:728
TStringConversion(const LegacyFromType *Source)
Definition StringConv.h:719
TStringConversion(const SrcBufferType *Source)
Definition StringConv.h:707
TStringConversion(UE::Core::Private::FFromStrCast, const FromType *Source, int32 SourceLen)
Definition StringConv.h:753
TStringConversion & operator=(const TStringConversion &)=delete
Definition StringConv.h:25
static void Convert(To *Dest, int32 DestLen, const CharType *Source, int32 SourceLen)
Definition StringConv.h:34
To ToType
Definition StringConv.h:28
From FromType
Definition StringConv.h:27
static int32 ConvertedLength(const CharType *Source, int32 SourceLen)
Definition StringConv.h:44
Definition StringConv.h:1239
void Apply() const
Definition StringConv.h:1256
TStringPassthru(ToType *InDest, int32 InDestLen, int32 InSrcLen)
Definition StringConv.h:1243
UE_FORCEINLINE_HINT FromType * Get() UE_LIFETIMEBOUND
Definition StringConv.h:1263
UE_FORCEINLINE_HINT TStringPassthru(TStringPassthru &&Other)
Definition StringConv.h:1251
Definition StringConv.h:832
UE_FORCEINLINE_HINT int32 Length() const
Definition StringConv.h:928
TStringPointer(const SrcBufferType *Source)
Definition StringConv.h:844
TStringPointer(TStringPointer &&Other)=default
TStringPointer(UE::Core::Private::FFromStrCast, const FromType *Source, int32 SourceLen)
Definition StringConv.h:883
TStringPointer(const SrcBufferType *Source, int32 SourceLen)
Definition StringConv.h:862
TStringPointer(FromRangeType &&Source)
Definition StringConv.h:901
UE_FORCEINLINE_HINT const ToType * Get() const UE_LIFETIMEBOUND
Definition StringConv.h:918
InToType ToType
Definition StringConv.h:837
InFromType FromType
Definition StringConv.h:836
Definition StringConv.h:547
InFromType FromType
Definition StringConv.h:552
InToType ToType
Definition StringConv.h:553
static int32 ConvertedLength(const SrcBufferType *Source, const int32 SourceLen)
Definition StringConv.h:583
static UE_FORCEINLINE_HINT void Convert(ToType *Dest, const int32 DestLen, const SrcBufferType *Source, const int32 SourceLen)
Definition StringConv.h:567
Definition StringConv.h:415
static int32 ConvertedLength(const SrcBufferType *Source, int32 SourceLen)
Definition StringConv.h:505
static int32 Utf16FromCodepoint(uint32 Codepoint, BufferType OutputIterator, uint32 OutputIteratorNumRemaining)
Definition StringConv.h:432
static UE_FORCEINLINE_HINT void Convert(ToType *Dest, int32 DestLen, const SrcBufferType *Source, int32 SourceLen)
Definition StringConv.h:491
InToType ToType
Definition StringConv.h:421
InFromType FromType
Definition StringConv.h:420
Definition StringConv.h:227
static UE_FORCEINLINE_HINT int32 ConvertedLength(const SrcBufferType *Source, int32 SourceLen)
Definition StringConv.h:342
static UE_FORCEINLINE_HINT int32 Convert(ToType *Dest, int32 DestLen, const SrcBufferType *Source, int32 SourceLen)
Definition StringConv.h:327
TCHAR FromType
Definition StringConv.h:232
ANSICHAR ToType
Definition StringConv.h:233
static int32 Utf8FromCodepoint(uint32 Codepoint, BufferType OutputIterator, uint32 OutputIteratorByteSizeRemaining)
Definition StringConv.h:244
static int32 Convert(IntendedToType *Dest, int32 DestLen, const SrcBufferType *Source, int32 SourceLen)
Definition StringConv.h:313
Definition StringConv.h:51
UE_FORCEINLINE_HINT bool IsHighSurrogate(const uint32 Codepoint)
Definition StringConv.h:64
UE_FORCEINLINE_HINT bool IsEncodedSurrogate(const uint32 Codepoint)
Definition StringConv.h:88
bool IsValidCodepoint(const uint32 Codepoint)
Definition StringConv.h:53
int32 InlineCombineSurrogates_Buffer(CharType *StrBuffer, int32 StrLen)
Definition StringConv.h:95
ConverterType::LegacyFromType GetLegacyFromType(typename ConverterType::LegacyFromType *)
UE_FORCEINLINE_HINT bool IsLowSurrogate(const uint32 Codepoint)
Definition StringConv.h:70
UE_FORCEINLINE_HINT uint32 EncodeSurrogate(const uint16 HighSurrogate, const uint16 LowSurrogate)
Definition StringConv.h:75
void DecodeSurrogate(const uint32 Codepoint, uint16 &OutHighSurrogate, uint16 &OutLowSurrogate)
Definition StringConv.h:80
void InlineCombineSurrogates_Array(TArray< TCHAR, AllocatorType > &StrBuffer)
Definition StringConv.h:154
implementation
Definition PlayInEditorLoadingScope.h:8
ENullTerminatedString
Definition StringConv.h:349
U16 Index
Definition radfft.cpp:71
static UE_FORCEINLINE_HINT void * Memmove(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:109
static int32 Strlen(const CharType *String)
Definition CString.h:1047
typename Converter::ToType Type
Definition StringConv.h:822
ToType Type
Definition StringConv.h:963
Definition ElementType.h:30
Definition IsCharEncodingCompatibleWith.h:65
Definition IsContiguousContainer.h:16
static constexpr bool Value
Definition IsContiguousContainer.h:20
Definition StringConv.h:178
FCountingOutputIterator()
Definition StringConv.h:179
const FCountingOutputIterator & operator++()
Definition StringConv.h:189
T operator=(T Val) const
Definition StringConv.h:206
friend int32 operator-(FCountingOutputIterator Lhs, FCountingOutputIterator Rhs)
Definition StringConv.h:211
const FCountingOutputIterator & operator+=(const int32 Amount)
Definition StringConv.h:199
const FCountingOutputIterator & operator*() const
Definition StringConv.h:184
const FCountingOutputIterator & operator++(int)
Definition StringConv.h:194
int32 GetCount() const
Definition StringConv.h:216
Definition StringConv.h:357