6#include "GenericPlatform/GenericPlatformStricmp.h"
7#include "GenericPlatform/GenericPlatformString.h"
20
21
22struct FStandardPlatformString :
public FGenericPlatformString
24 using FGenericPlatformString::Stricmp;
25 using FGenericPlatformString::Strncmp;
26 using FGenericPlatformString::Strnicmp;
28 template <
typename CharType>
29 static inline CharType* Strupr(CharType* Dest, SIZE_T DestCount)
31 for (CharType* Char = Dest; *Char && DestCount > 0; Char++, DestCount--)
33 *Char = TChar<CharType>::ToUpper(*Char);
41
42
43 static FORCEINLINE WIDECHAR* Strcpy(WIDECHAR* Dest, SIZE_T DestCount,
const WIDECHAR* Src)
46PRAGMA_DISABLE_DEPRECATION_WARNINGS
47 return wcscpy(Dest, Src);
48PRAGMA_ENABLE_DEPRECATION_WARNINGS
51 static FORCEINLINE WIDECHAR* Strncpy(WIDECHAR* Dest,
const WIDECHAR* Src, SIZE_T MaxLen)
54PRAGMA_DISABLE_DEPRECATION_WARNINGS
55 wcsncpy(Dest, Src, MaxLen-1);
56PRAGMA_ENABLE_DEPRECATION_WARNINGS
61 static FORCEINLINE WIDECHAR* Strcat(WIDECHAR* Dest, SIZE_T DestCount,
const WIDECHAR* Src)
64PRAGMA_DISABLE_DEPRECATION_WARNINGS
65 return (WIDECHAR*)wcscat( Dest, Src );
66PRAGMA_ENABLE_DEPRECATION_WARNINGS
69 static FORCEINLINE int32 Strcmp(
const WIDECHAR* String1,
const WIDECHAR* String2 )
71 return wcscmp(String1, String2);
74 static FORCEINLINE int32 Strncmp(
const WIDECHAR* String1,
const WIDECHAR* String2, SIZE_T Count )
76 return wcsncmp( String1, String2, Count );
79 static FORCEINLINE int32 Strlen(
const WIDECHAR* String )
81 return (int32)wcslen( String );
84 static FORCEINLINE int32 Strnlen(
const WIDECHAR* String, SIZE_T StringSize )
86 return (int32)wcsnlen_s( String, StringSize );
89 static FORCEINLINE
const WIDECHAR* Strstr(
const WIDECHAR* String,
const WIDECHAR* Find)
91 return wcsstr( String, Find );
94 static FORCEINLINE
const WIDECHAR* Strchr(
const WIDECHAR* String, WIDECHAR C)
96 return wcschr( String, C );
99 static FORCEINLINE
const WIDECHAR* Strrchr(
const WIDECHAR* String, WIDECHAR C)
101 return wcsrchr( String, C );
104 static FORCEINLINE int32 Atoi(
const WIDECHAR* String)
106 return (int32)wcstol( String, NULL, 10 );
109 static FORCEINLINE int64 Atoi64(
const WIDECHAR* String)
111 return wcstoll( String, NULL, 10 );
114 static FORCEINLINE
float Atof(
const WIDECHAR* String)
116 return wcstof( String, NULL );
119 static FORCEINLINE
double Atod(
const WIDECHAR* String)
121 return wcstod( String, NULL );
124 static FORCEINLINE int32 Strtoi(
const WIDECHAR* Start, WIDECHAR** End, int32 Base )
126 return (int32)wcstol( Start, End, Base );
129 static FORCEINLINE int64 Strtoi64(
const WIDECHAR* Start, WIDECHAR** End, int32 Base )
131 return wcstoll( Start, End, Base );
134 static FORCEINLINE uint64 Strtoui64(
const WIDECHAR* Start, WIDECHAR** End, int32 Base )
136 return wcstoull( Start, End, Base );
139 static FORCEINLINE WIDECHAR* Strtok(WIDECHAR* StrToken,
const WIDECHAR* Delim, WIDECHAR** Context)
142PRAGMA_DISABLE_DEPRECATION_WARNINGS
143 return wcstok(StrToken, Delim, Context);
144PRAGMA_ENABLE_DEPRECATION_WARNINGS
147#if PLATFORM_USE_SYSTEM_VSWPRINTF
148 static int32 GetVarArgs( WIDECHAR* Dest, SIZE_T DestSize,
const WIDECHAR*& Fmt, va_list ArgPtr )
150#if PLATFORM_USE_LS_SPEC_FOR_WIDECHAR
152 const WIDECHAR* OldFormat = Fmt;
153 WIDECHAR* NewFormat = (WIDECHAR*)alloca((Strlen(Fmt) * 2 + 1) *
sizeof(WIDECHAR));
157 for (; *OldFormat != 0; NewIndex++, OldFormat++)
160 if (OldFormat[0] == LITERAL(WIDECHAR,
'%'))
162 NewFormat[NewIndex++] = *OldFormat++;
164 if (*OldFormat == LITERAL(WIDECHAR,
'%'))
166 NewFormat[NewIndex] = *OldFormat;
170 const WIDECHAR* NextChar = OldFormat;
172 while(*NextChar != 0 && !FChar::IsAlpha(*NextChar))
174 NewFormat[NewIndex++] = *NextChar;
178 if (*NextChar == LITERAL(WIDECHAR,
's') || *NextChar == LITERAL(WIDECHAR,
'c'))
180 NewFormat[NewIndex++] = LITERAL(WIDECHAR,
'l');
181 NewFormat[NewIndex] = *NextChar;
183 else if (*NextChar == LITERAL(WIDECHAR,
'S'))
185 NewFormat[NewIndex] = LITERAL(WIDECHAR,
's');
189 NewFormat[NewIndex] = *NextChar;
192 OldFormat = NextChar;
197 NewFormat[NewIndex] = *OldFormat;
200 NewFormat[NewIndex] = 0;
201 int32 Result = vswprintf( Dest, DestSize, NewFormat, ArgPtr);
203 int32 Result = vswprintf( Dest, DestSize, Fmt, ArgPtr);
209 static int32 GetVarArgs( WIDECHAR* Dest, SIZE_T DestSize,
const WIDECHAR*& Fmt, va_list ArgPtr );
213
214
215 static FORCEINLINE ANSICHAR* Strcpy(ANSICHAR* Dest, SIZE_T DestCount,
const ANSICHAR* Src)
218PRAGMA_DISABLE_DEPRECATION_WARNINGS
219 return strcpy( Dest, Src );
220PRAGMA_ENABLE_DEPRECATION_WARNINGS
223 static FORCEINLINE ANSICHAR* Strncpy(ANSICHAR* Dest,
const ANSICHAR* Src, SIZE_T MaxLen)
226PRAGMA_DISABLE_DEPRECATION_WARNINGS
227 ::strncpy(Dest, Src, MaxLen);
228PRAGMA_ENABLE_DEPRECATION_WARNINGS
233 static FORCEINLINE ANSICHAR* Strcat(ANSICHAR* Dest, SIZE_T DestCount,
const ANSICHAR* Src)
236PRAGMA_DISABLE_DEPRECATION_WARNINGS
237 return strcat( Dest, Src );
238PRAGMA_ENABLE_DEPRECATION_WARNINGS
241 static FORCEINLINE int32 Strcmp(
const ANSICHAR* String1,
const ANSICHAR* String2 )
243 return strcmp(String1, String2);
246 static FORCEINLINE int32 Strncmp(
const ANSICHAR* String1,
const ANSICHAR* String2, SIZE_T Count )
248 return strncmp( String1, String2, Count );
251 static FORCEINLINE int32 Strlen(
const ANSICHAR* String )
253 return (int32)strlen( String );
256 static FORCEINLINE int32 Strnlen(
const ANSICHAR* String, SIZE_T StringSize )
258 return (int32)strnlen_s( String, StringSize );
261 static FORCEINLINE
const ANSICHAR* Strstr(
const ANSICHAR* String,
const ANSICHAR* Find)
263 return strstr(String, Find);
266 static FORCEINLINE
const ANSICHAR* Strchr(
const ANSICHAR* String, ANSICHAR C)
268 return strchr(String, C);
271 static FORCEINLINE
const ANSICHAR* Strrchr(
const ANSICHAR* String, ANSICHAR C)
273 return strrchr(String, C);
276 static FORCEINLINE int32 Atoi(
const ANSICHAR* String)
278 return atoi( String );
281 static FORCEINLINE int64 Atoi64(
const ANSICHAR* String)
283 return strtoll( String, NULL, 10 );
286 static FORCEINLINE
float Atof(
const ANSICHAR* String)
288 return (
float)atof( String );
291 static FORCEINLINE
double Atod(
const ANSICHAR* String)
293 return atof( String );
296 static FORCEINLINE int32 Strtoi(
const ANSICHAR* Start, ANSICHAR** End, int32 Base )
298 return (int32)strtol( Start, End, Base );
301 static FORCEINLINE int64 Strtoi64(
const ANSICHAR* Start, ANSICHAR** End, int32 Base )
303 return strtoll(Start, End, Base);
306 static FORCEINLINE uint64 Strtoui64(
const ANSICHAR* Start, ANSICHAR** End, int32 Base )
308 return strtoull(Start, End, Base);
311 static FORCEINLINE ANSICHAR* Strtok(ANSICHAR* StrToken,
const ANSICHAR* Delim, ANSICHAR** Context)
314PRAGMA_DISABLE_DEPRECATION_WARNINGS
315 return strtok(StrToken, Delim);
316PRAGMA_ENABLE_DEPRECATION_WARNINGS
319 static int32 GetVarArgs( ANSICHAR* Dest, SIZE_T DestSize,
const ANSICHAR*& Fmt, va_list ArgPtr )
321 int32 Result = vsnprintf(Dest, DestSize, Fmt, ArgPtr);
323 return (Result != -1 && Result < (int32)DestSize) ? Result : -1;
327
328
329 static FORCEINLINE UTF8CHAR* Strcpy(UTF8CHAR* Dest, SIZE_T DestCount,
const UTF8CHAR* Src)
331 return (UTF8CHAR*)Strcpy((ANSICHAR*)Dest, DestCount, (
const ANSICHAR*)Src);
334 static FORCEINLINE UTF8CHAR* Strncpy(UTF8CHAR* Dest,
const UTF8CHAR* Src, SIZE_T MaxLen)
336 return (UTF8CHAR*)Strncpy((ANSICHAR*)Dest, (
const ANSICHAR*)Src, MaxLen);
339 static FORCEINLINE UTF8CHAR* Strcat(UTF8CHAR* Dest, SIZE_T DestCount,
const UTF8CHAR* Src)
341 return (UTF8CHAR*)Strcat((ANSICHAR*)Dest, DestCount, (
const ANSICHAR*)Src);
344 static FORCEINLINE int32 Strcmp(
const UTF8CHAR* String1,
const UTF8CHAR* String2)
346 return Strcmp((
const ANSICHAR*)String1, (
const ANSICHAR*)String2);
349 static FORCEINLINE int32 Strncmp(
const UTF8CHAR* String1,
const UTF8CHAR* String2, SIZE_T Count)
351 return Strncmp((
const ANSICHAR*)String1, (
const ANSICHAR*)String2, Count);
354 static FORCEINLINE int32 Strlen(
const UTF8CHAR* String)
356 return Strlen((
const ANSICHAR*)String);
359 static FORCEINLINE int32 Strnlen(
const UTF8CHAR* String, SIZE_T StringSize)
361 return Strnlen((
const ANSICHAR*)String, StringSize);
364 static FORCEINLINE
const UTF8CHAR* Strstr(
const UTF8CHAR* String,
const UTF8CHAR* Find)
366 return (
const UTF8CHAR*)Strstr((
const ANSICHAR*)String, (
const ANSICHAR*)Find);
369 static FORCEINLINE
const UTF8CHAR* Strchr(
const UTF8CHAR* String, UTF8CHAR C)
371 return (
const UTF8CHAR*)Strchr((
const ANSICHAR*)String, (ANSICHAR)C);
374 static FORCEINLINE
const UTF8CHAR* Strrchr(
const UTF8CHAR* String, UTF8CHAR C)
376 return (
const UTF8CHAR*)Strrchr((
const ANSICHAR*)String, (ANSICHAR)C);
379 static FORCEINLINE int32 Atoi(
const UTF8CHAR* String)
381 return Atoi((
const ANSICHAR*)String);
384 static FORCEINLINE int64 Atoi64(
const UTF8CHAR* String)
386 return Atoi64((
const ANSICHAR*)String);
389 static FORCEINLINE
float Atof(
const UTF8CHAR* String)
391 return Atof((
const ANSICHAR*)String);
394 static FORCEINLINE
double Atod(
const UTF8CHAR* String)
396 return Atod((
const ANSICHAR*)String);
399 static FORCEINLINE int32 Strtoi(
const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
401 return Strtoi((
const ANSICHAR*)Start, (ANSICHAR**)End, Base);
404 static FORCEINLINE int64 Strtoi64(
const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
406 return Strtoi64((
const ANSICHAR*)Start, (ANSICHAR**)End, Base);
409 static FORCEINLINE uint64 Strtoui64(
const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
411 return Strtoui64((
const ANSICHAR*)Start, (ANSICHAR**)End, Base);
414 static FORCEINLINE UTF8CHAR* Strtok(UTF8CHAR* StrToken,
const UTF8CHAR* Delim, UTF8CHAR** Context)
416 return (UTF8CHAR*)Strtok((ANSICHAR*)StrToken, (
const ANSICHAR*)Delim, (ANSICHAR**)Context);
419 static FORCEINLINE int32 GetVarArgs(UTF8CHAR* Dest, SIZE_T DestSize,
const UTF8CHAR*& Fmt, va_list ArgPtr)
421 return GetVarArgs((ANSICHAR*)Dest, DestSize, *(
const ANSICHAR**)&Fmt, ArgPtr);
425
426
428 static FORCEINLINE int32 Strlen(
const UCS2CHAR* String )
439 static FORCEINLINE int32 Strnlen(
const UCS2CHAR* String, SIZE_T StringSize )
442 while (StringSize-- > 0 && *String++)