UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ApplePlatformString.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
8#include "Misc/OutputDevice.h"
9
10#if PLATFORM_MAC
12#elif PLATFORM_IOS
14#endif
15
16static_assert(PLATFORM_TCHAR_IS_CHAR16, "TCHAR must be CHAR16.");
17
18#ifdef __OBJC__
19#import <Foundation/NSString.h>
20
21class FString;
22
23@interface NSString (FString_Extensions)
24
28+ (NSString*) stringWithTCHARString:(const TCHAR*)MyTCHARString;
29
33+ (NSString*) stringWithFString:(const FString&)MyFString;
34
35@end
36#endif
37
38
42struct FApplePlatformString : public FGenericWidePlatformString
43{
44 // These should be replaced with equivalent Convert and ConvertedLength functions when we properly support variable-length encodings.
45/* static void WideCharToMultiByte(const TCHAR *Source, uint32 LengthWM1, ANSICHAR *Dest, uint32 LengthA)
46 {
47 CFStringRef CFSource = CFStringCreateWithBytes( kCFAllocatorDefault, ( const uint8 *)Source, LengthWM1 * sizeof( TCHAR ), kCFStringEncodingUTF32LE, false );
48 check(CFSource);
49 const SIZE_T CFSourceLength = CFStringGetLength( CFSource );
50 LengthWM1 = LengthWM1 < CFSourceLength ? LengthWM1 : CFSourceLength;
51 CFRange Range = CFRangeMake( 0, LengthWM1 );
52 CFIndex ActualLength = 0;
53 CFIndex Converted = CFStringGetBytes( CFSource, Range, kCFStringEncodingUTF8, '?', false, NULL, LengthA, &ActualLength );
54 check(Converted == LengthWM1 && ActualLength <= LengthA);
55 CFStringGetBytes( CFSource, Range, kCFStringEncodingUTF8, '?', false, ( uint8 *)Dest, LengthA, &ActualLength );
56 Dest[ActualLength] = 0;
57 CFRelease( CFSource );
58 }
59 static void MultiByteToWideChar(const ANSICHAR *Source, TCHAR *Dest, uint32 LengthM1)
60 {
61 CFStringRef CFSource = CFStringCreateWithBytes( kCFAllocatorDefault, ( const uint8 *)Source, LengthM1, kCFStringEncodingUTF8, false );
62 check(CFSource);
63 const SIZE_T CFSourceLength = CFStringGetLength( CFSource );
64 LengthM1 = LengthM1 < CFSourceLength ? LengthM1 : CFSourceLength;
65 CFRange Range = CFRangeMake( 0, LengthM1 );
66 CFIndex ActualLength = 0;
67 CFStringGetBytes( CFSource, Range, kCFStringEncodingUTF32LE, '?', false, NULL, LengthM1 * sizeof( TCHAR ), &ActualLength );
68 check(ActualLength <= (LengthM1 * sizeof( TCHAR )));
69 CFStringGetBytes( CFSource, Range, kCFStringEncodingUTF32LE, '?', false, ( uint8 *)Dest, LengthM1 * sizeof( TCHAR ), &ActualLength );
70 uint8* Ptr = (uint8*)Dest;
71 Ptr[ActualLength] = Ptr[ActualLength + 1] = Ptr[ActualLength + 2] = Ptr[ActualLength + 3] = 0;
72 CFRelease( CFSource );
73 }*/
75 {
77 CFRange Range = CFRangeMake( 0, Length );
78 CFStringGetBytes( CFStr, Range, sizeof( TCHAR ) == 4 ? kCFStringEncodingUTF32LE : kCFStringEncodingUnicode, '?', false, ( uint8 *)TChar, Length * sizeof( TCHAR ) + 1, NULL );
79 TChar[Length] = 0;
80 }
82 {
83 const SIZE_T Length = Strlen( TChar );
85 // we are getting some crashes on strings that aren't converting - so, instead of crashing, print them out instead
86 ensureMsgf(String, TEXT("Failed to allocated CFString for '%s' -- Length id %d"), TChar ? TChar : TEXT("nullptr"), Length);
87 return String;
88 }
89};
90
92
93// Format specifiers to be able to print values of these types correctly, for example when using UE_LOG.
94// SIZE_T format specifier
95#define SIZE_T_FMT "zu"
96// SIZE_T format specifier for lowercase hexadecimal output
97#define SIZE_T_x_FMT "zx"
98// SIZE_T format specifier for uppercase hexadecimal output
99#define SIZE_T_X_FMT "zX"
100
101// SSIZE_T format specifier
102#define SSIZE_T_FMT "lld"
103// SSIZE_T format specifier for lowercase hexadecimal output
104#define SSIZE_T_x_FMT "llx"
105// SSIZE_T format specifier for uppercase hexadecimal output
106#define SSIZE_T_X_FMT "llX"
107
108// PTRINT format specifier for decimal output
109#define PTRINT_FMT SSIZE_T_FMT
110// PTRINT format specifier for lowercase hexadecimal output
111#define PTRINT_x_FMT SSIZE_T_x_FMT
112// PTRINT format specifier for uppercase hexadecimal output
113#define PTRINT_X_FMT SSIZE_T_X_FMT
114
115// UPTRINT format specifier for decimal output
116#define UPTRINT_FMT "llu"
117// UPTRINT format specifier for lowercase hexadecimal output
118#define UPTRINT_x_FMT "llx"
119// UPTRINT format specifier for uppercase hexadecimal output
120#define UPTRINT_X_FMT "llX"
121
122// int64 format specifier for decimal output
123#define INT64_FMT SSIZE_T_FMT
124// int64 format specifier for lowercase hexadecimal output
125#define INT64_x_FMT SSIZE_T_x_FMT
126// int64 format specifier for uppercase hexadecimal output
127#define INT64_X_FMT SSIZE_T_X_FMT
128
129// uint64 format specifier for decimal output
130#define UINT64_FMT "llu"
131// uint64 format specifier for lowercase hexadecimal output
132#define UINT64_x_FMT "llx"
133// uint64 format specifier for uppercase hexadecimal output
134#define UINT64_X_FMT "llX"
#define NULL
Definition oodle2base.h:134
FGenericWidePlatformString FPlatformString
Definition AndroidPlatformString.h:12
#define PLATFORM_TCHAR_IS_CHAR16
Definition AndroidPlatform.h:47
#define ensureMsgf( InExpression, InFormat,...)
Definition AssertionMacros.h:465
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint8_t uint8
Definition binka_ue_file_header.h:8
@ false
Definition radaudio_common.h:23
Definition ApplePlatformString.h:43
static CFStringRef TCHARToCFString(const TCHAR *TChar)
Definition ApplePlatformString.h:81
static void CFStringToTCHAR(CFStringRef CFStr, TCHAR *TChar)
Definition ApplePlatformString.h:74
Definition Char.h:76