6#include "GenericPlatform/GenericPlatformStricmp.h"
7#include "GenericPlatform/GenericPlatformString.h"
8#include "HAL/PlatformCrt.h"
9#include "Misc/AssertionMacros.h"
15
16
17struct FGenericWidePlatformString :
public FGenericPlatformString
19 using FGenericPlatformString::Stricmp;
20 using FGenericPlatformString::Strncmp;
21 using FGenericPlatformString::Strnicmp;
23 template <
typename CharType>
24 static inline CharType* Strupr(CharType* Dest, SIZE_T DestCount)
26 for (CharType* Char = Dest; *Char && DestCount > 0; Char++, DestCount--)
28 *Char = TChar<CharType>::ToUpper(*Char);
36
37
38 static WIDECHAR* Strcpy(WIDECHAR* Dest, SIZE_T DestCount,
const WIDECHAR* Src);
39 static WIDECHAR* Strncpy(WIDECHAR* Dest,
const WIDECHAR* Src, SIZE_T MaxLen);
40 static WIDECHAR* Strcat(WIDECHAR* Dest, SIZE_T DestCount,
const WIDECHAR* Src);
42 static int32 Strcmp(
const WIDECHAR* String1,
const WIDECHAR* String2 )
45 for (; *String1 || *String2; String1++, String2++)
47 WIDECHAR A = *String1, B = *String2;
56 static int32 Strlen(
const WIDECHAR* String )
69 static int32 Strnlen(
const WIDECHAR* String, SIZE_T StringSize )
77 while (StringSize-- > 0 && *String++);
82#if PLATFORM_TCHAR_IS_CHAR16
83 static int32 Strlen(
const wchar_t* String )
96 static int32 Strnlen(
const wchar_t* String, SIZE_T StringSize )
104 while (StringSize-- > 0 && *String++);
110 static const WIDECHAR* Strstr(
const WIDECHAR* String,
const WIDECHAR* Find)
112 WIDECHAR Char1, Char2;
113 if ((Char1 = *Find++) != 0)
115 size_t Length = Strlen(Find);
121 if ((Char2 = *String++) == 0)
126 while (Char1 != Char2);
128 while (Strncmp(String, Find, Length) != 0);
136 static const WIDECHAR* Strchr(
const WIDECHAR* String, WIDECHAR C)
138 while (*String != C && *String != 0)
143 return (*String == C) ? String :
nullptr;
146 static const WIDECHAR* Strrchr(
const WIDECHAR* String, WIDECHAR C)
148 const WIDECHAR *Last =
nullptr;
168 static int32 Strtoi(
const WIDECHAR* Start, WIDECHAR** End, int32 Base);
169 static int64 Strtoi64(
const WIDECHAR* Start, WIDECHAR** End, int32 Base);
171 static uint64 Strtoui64(
const WIDECHAR* Start, WIDECHAR** End, int32 Base );
172 static float Atof(
const WIDECHAR* String);
173 static double Atod(
const WIDECHAR* String);
175 static FORCEINLINE int32 Atoi(
const WIDECHAR* String)
177 return Strtoi( String, NULL, 10 );
180 static FORCEINLINE int64 Atoi64(
const WIDECHAR* String)
182 return Strtoi64( String, NULL, 10 );
187 static WIDECHAR* Strtok( WIDECHAR* StrToken,
const WIDECHAR* Delim, WIDECHAR** Context );
189 static int32 GetVarArgs(WIDECHAR* Dest, SIZE_T DestSize,
const WIDECHAR*& Fmt, va_list ArgPtr);
192
193
194 static FORCEINLINE ANSICHAR* Strcpy(ANSICHAR* Dest, SIZE_T DestCount,
const ANSICHAR* Src)
197PRAGMA_DISABLE_DEPRECATION_WARNINGS
198 return strcpy( Dest, Src );
199PRAGMA_ENABLE_DEPRECATION_WARNINGS
202 static FORCEINLINE ANSICHAR* Strncpy(ANSICHAR* Dest,
const ANSICHAR* Src, SIZE_T MaxLen)
205PRAGMA_DISABLE_DEPRECATION_WARNINGS
206 ::strncpy(Dest, Src, MaxLen);
207PRAGMA_ENABLE_DEPRECATION_WARNINGS
212 static FORCEINLINE ANSICHAR* Strcat(ANSICHAR* Dest, SIZE_T DestCount,
const ANSICHAR* Src)
215PRAGMA_DISABLE_DEPRECATION_WARNINGS
216 return strcat( Dest, Src );
217PRAGMA_ENABLE_DEPRECATION_WARNINGS
220 static FORCEINLINE int32 Strcmp(
const ANSICHAR* String1,
const ANSICHAR* String2 )
222 return strcmp(String1, String2);
225 static FORCEINLINE int32 Strncmp(
const ANSICHAR* String1,
const ANSICHAR* String2, SIZE_T Count )
227 return strncmp( String1, String2, Count );
230 static FORCEINLINE int32 Strlen(
const ANSICHAR* String )
232 return strlen( String );
235 static FORCEINLINE int32 Strnlen(
const ANSICHAR* String, SIZE_T StringSize )
237 return strnlen( String, StringSize );
240 static FORCEINLINE
const ANSICHAR* Strstr(
const ANSICHAR* String,
const ANSICHAR* Find)
242 return strstr(String, Find);
245 static FORCEINLINE
const ANSICHAR* Strchr(
const ANSICHAR* String, ANSICHAR C)
247 return strchr(String, C);
250 static FORCEINLINE
const ANSICHAR* Strrchr(
const ANSICHAR* String, ANSICHAR C)
252 return strrchr(String, C);
255 static FORCEINLINE int32 Atoi(
const ANSICHAR* String)
257 return atoi( String );
260 static FORCEINLINE int64 Atoi64(
const ANSICHAR* String)
262 return strtoll( String, NULL, 10 );
265 static FORCEINLINE
float Atof(
const ANSICHAR* String)
267 return (
float)atof( String );
270 static FORCEINLINE
double Atod(
const ANSICHAR* String)
272 return atof( String );
275 static FORCEINLINE int32 Strtoi(
const ANSICHAR* Start, ANSICHAR** End, int32 Base )
277 return strtol( Start, End, Base );
280 static FORCEINLINE int64 Strtoi64(
const ANSICHAR* Start, ANSICHAR** End, int32 Base )
282 return strtoll(Start, End, Base);
285 static FORCEINLINE uint64 Strtoui64(
const ANSICHAR* Start, ANSICHAR** End, int32 Base )
287 return strtoull(Start, End, Base);
290 static FORCEINLINE ANSICHAR* Strtok(ANSICHAR* StrToken,
const ANSICHAR* Delim, ANSICHAR** Context)
293PRAGMA_DISABLE_DEPRECATION_WARNINGS
294 return strtok(StrToken, Delim);
295PRAGMA_ENABLE_DEPRECATION_WARNINGS
298 static int32 GetVarArgs( ANSICHAR* Dest, SIZE_T DestSize,
const ANSICHAR*& Fmt, va_list ArgPtr )
300 int32 Result = vsnprintf(Dest, DestSize, Fmt, ArgPtr);
302 return (Result != -1 && Result < (int32)DestSize) ? Result : -1;
306
307
308 static FORCEINLINE UTF8CHAR* Strcpy(UTF8CHAR* Dest, SIZE_T DestCount,
const UTF8CHAR* Src)
310 return (UTF8CHAR*)Strcpy((ANSICHAR*)Dest, DestCount, (
const ANSICHAR*)Src);
313 static FORCEINLINE UTF8CHAR* Strncpy(UTF8CHAR* Dest,
const UTF8CHAR* Src, SIZE_T MaxLen)
315 return (UTF8CHAR*)Strncpy((ANSICHAR*)Dest, (
const ANSICHAR*)Src, MaxLen);
318 static FORCEINLINE UTF8CHAR* Strcat(UTF8CHAR* Dest, SIZE_T DestCount,
const UTF8CHAR* Src)
320 return (UTF8CHAR*)Strcat((ANSICHAR*)Dest, DestCount, (
const ANSICHAR*)Src);
323 static FORCEINLINE int32 Strcmp(
const UTF8CHAR* String1,
const UTF8CHAR* String2)
325 return Strcmp((
const ANSICHAR*)String1, (
const ANSICHAR*)String2);
328 static FORCEINLINE int32 Strncmp(
const UTF8CHAR* String1,
const UTF8CHAR* String2, SIZE_T Count)
330 return Strncmp((
const ANSICHAR*)String1, (
const ANSICHAR*)String2, Count);
333 static FORCEINLINE int32 Strlen(
const UTF8CHAR* String)
335 return Strlen((
const ANSICHAR*)String);
338 static FORCEINLINE int32 Strnlen(
const UTF8CHAR* String, SIZE_T StringSize)
340 return Strnlen((
const ANSICHAR*)String, StringSize);
343 static FORCEINLINE
const UTF8CHAR* Strstr(
const UTF8CHAR* String,
const UTF8CHAR* Find)
345 return (
const UTF8CHAR*)Strstr((
const ANSICHAR*)String, (
const ANSICHAR*)Find);
348 static FORCEINLINE
const UTF8CHAR* Strchr(
const UTF8CHAR* String, UTF8CHAR C)
350 return (
const UTF8CHAR*)Strchr((
const ANSICHAR*)String, (ANSICHAR)C);
353 static FORCEINLINE
const UTF8CHAR* Strrchr(
const UTF8CHAR* String, UTF8CHAR C)
355 return (
const UTF8CHAR*)Strrchr((
const ANSICHAR*)String, (ANSICHAR)C);
358 static FORCEINLINE int32 Atoi(
const UTF8CHAR* String)
360 return Atoi((
const ANSICHAR*)String);
363 static FORCEINLINE int64 Atoi64(
const UTF8CHAR* String)
365 return Atoi64((
const ANSICHAR*)String);
368 static FORCEINLINE
float Atof(
const UTF8CHAR* String)
370 return Atof((
const ANSICHAR*)String);
373 static FORCEINLINE
double Atod(
const UTF8CHAR* String)
375 return Atod((
const ANSICHAR*)String);
378 static FORCEINLINE int32 Strtoi(
const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
380 return Strtoi((
const ANSICHAR*)Start, (ANSICHAR**)End, Base);
383 static FORCEINLINE int64 Strtoi64(
const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
385 return Strtoi64((
const ANSICHAR*)Start, (ANSICHAR**)End, Base);
388 static FORCEINLINE uint64 Strtoui64(
const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
390 return Strtoui64((
const ANSICHAR*)Start, (ANSICHAR**)End, Base);
393 static FORCEINLINE UTF8CHAR* Strtok(UTF8CHAR* StrToken,
const UTF8CHAR* Delim, UTF8CHAR** Context)
395 return (UTF8CHAR*)Strtok((ANSICHAR*)StrToken, (
const ANSICHAR*)Delim, (ANSICHAR**)Context);
398 static FORCEINLINE int32 GetVarArgs(UTF8CHAR* Dest, SIZE_T DestSize,
const UTF8CHAR*& Fmt, va_list ArgPtr)
400 return GetVarArgs((ANSICHAR*)Dest, DestSize, *(
const ANSICHAR**)&Fmt, ArgPtr);
404
405
407 static FORCEINLINE int32 Strlen(
const UCS2CHAR* String )
418 static FORCEINLINE int32 Strnlen(
const UCS2CHAR* String, SIZE_T StringSize )
421 while (StringSize-- > 0 && *String++)