Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
StandardPlatformString.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"
6#include "GenericPlatform/GenericPlatformStricmp.h"
7#include "GenericPlatform/GenericPlatformString.h"
8#include "Misc/Char.h"
9
10// IWYU pragma: begin_exports
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <wchar.h>
15// IWYU pragma: end_exports
16
18
19/**
20* Standard implementation
21**/
22struct FStandardPlatformString : public FGenericPlatformString
23{
24 using FGenericPlatformString::Stricmp;
25 using FGenericPlatformString::Strncmp;
26 using FGenericPlatformString::Strnicmp;
27
28 template <typename CharType>
29 static inline CharType* Strupr(CharType* Dest, SIZE_T DestCount)
30 {
31 for (CharType* Char = Dest; *Char && DestCount > 0; Char++, DestCount--)
32 {
33 *Char = TChar<CharType>::ToUpper(*Char);
34 }
35 return Dest;
36 }
37
38public:
39
40 /**
41 * Unicode implementation
42 **/
43 static FORCEINLINE WIDECHAR* Strcpy(WIDECHAR* Dest, SIZE_T DestCount, const WIDECHAR* Src)
44 {
45// Skip suggestions about using wcscpy_s instead.
46PRAGMA_DISABLE_DEPRECATION_WARNINGS
47 return wcscpy(Dest, Src);
48PRAGMA_ENABLE_DEPRECATION_WARNINGS
49 }
50
51 static FORCEINLINE WIDECHAR* Strncpy(WIDECHAR* Dest, const WIDECHAR* Src, SIZE_T MaxLen)
52 {
53// Skip suggestions about using wcsncpy_s instead.
54PRAGMA_DISABLE_DEPRECATION_WARNINGS
55 wcsncpy(Dest, Src, MaxLen-1);
56PRAGMA_ENABLE_DEPRECATION_WARNINGS
57 Dest[MaxLen-1]=0;
58 return Dest;
59 }
60
61 static FORCEINLINE WIDECHAR* Strcat(WIDECHAR* Dest, SIZE_T DestCount, const WIDECHAR* Src)
62 {
63// Skip suggestions about using wcscat_s instead.
64PRAGMA_DISABLE_DEPRECATION_WARNINGS
65 return (WIDECHAR*)wcscat( Dest, Src );
66PRAGMA_ENABLE_DEPRECATION_WARNINGS
67 }
68
69 static FORCEINLINE int32 Strcmp( const WIDECHAR* String1, const WIDECHAR* String2 )
70 {
71 return wcscmp(String1, String2);
72 }
73
74 static FORCEINLINE int32 Strncmp( const WIDECHAR* String1, const WIDECHAR* String2, SIZE_T Count )
75 {
76 return wcsncmp( String1, String2, Count );
77 }
78
79 static FORCEINLINE int32 Strlen( const WIDECHAR* String )
80 {
81 return (int32)wcslen( String );
82 }
83
84 static FORCEINLINE int32 Strnlen( const WIDECHAR* String, SIZE_T StringSize )
85 {
86 return (int32)wcsnlen_s( String, StringSize );
87 }
88
89 static FORCEINLINE const WIDECHAR* Strstr( const WIDECHAR* String, const WIDECHAR* Find)
90 {
91 return wcsstr( String, Find );
92 }
93
94 static FORCEINLINE const WIDECHAR* Strchr( const WIDECHAR* String, WIDECHAR C)
95 {
96 return wcschr( String, C );
97 }
98
99 static FORCEINLINE const WIDECHAR* Strrchr( const WIDECHAR* String, WIDECHAR C)
100 {
101 return wcsrchr( String, C );
102 }
103
104 static FORCEINLINE int32 Atoi(const WIDECHAR* String)
105 {
106 return (int32)wcstol( String, NULL, 10 );
107 }
108
109 static FORCEINLINE int64 Atoi64(const WIDECHAR* String)
110 {
111 return wcstoll( String, NULL, 10 );
112 }
113
114 static FORCEINLINE float Atof(const WIDECHAR* String)
115 {
116 return wcstof( String, NULL );
117 }
118
119 static FORCEINLINE double Atod(const WIDECHAR* String)
120 {
121 return wcstod( String, NULL );
122 }
123
124 static FORCEINLINE int32 Strtoi( const WIDECHAR* Start, WIDECHAR** End, int32 Base )
125 {
126 return (int32)wcstol( Start, End, Base );
127 }
128
129 static FORCEINLINE int64 Strtoi64( const WIDECHAR* Start, WIDECHAR** End, int32 Base )
130 {
131 return wcstoll( Start, End, Base );
132 }
133
134 static FORCEINLINE uint64 Strtoui64( const WIDECHAR* Start, WIDECHAR** End, int32 Base )
135 {
136 return wcstoull( Start, End, Base );
137 }
138
139 static FORCEINLINE WIDECHAR* Strtok(WIDECHAR* StrToken, const WIDECHAR* Delim, WIDECHAR** Context)
140 {
141// Skip suggestions about using wcstok_s instead.
142PRAGMA_DISABLE_DEPRECATION_WARNINGS
143 return wcstok(StrToken, Delim, Context);
144PRAGMA_ENABLE_DEPRECATION_WARNINGS
145 }
146
147#if PLATFORM_USE_SYSTEM_VSWPRINTF
148 static int32 GetVarArgs( WIDECHAR* Dest, SIZE_T DestSize, const WIDECHAR*& Fmt, va_list ArgPtr )
149 {
150#if PLATFORM_USE_LS_SPEC_FOR_WIDECHAR
151 // fix up the Fmt string, as fast as possible, without using an FString
152 const WIDECHAR* OldFormat = Fmt;
153 WIDECHAR* NewFormat = (WIDECHAR*)alloca((Strlen(Fmt) * 2 + 1) * sizeof(WIDECHAR));
154
155 int32 NewIndex = 0;
156
157 for (; *OldFormat != 0; NewIndex++, OldFormat++)
158 {
159 // fix up %s -> %ls and %c -> %lc
160 if (OldFormat[0] == LITERAL(WIDECHAR, '%'))
161 {
162 NewFormat[NewIndex++] = *OldFormat++;
163
164 if (*OldFormat == LITERAL(WIDECHAR, '%'))
165 {
166 NewFormat[NewIndex] = *OldFormat;
167 }
168 else
169 {
170 const WIDECHAR* NextChar = OldFormat;
171
172 while(*NextChar != 0 && !FChar::IsAlpha(*NextChar))
173 {
174 NewFormat[NewIndex++] = *NextChar;
175 ++NextChar;
176 };
177
178 if (*NextChar == LITERAL(WIDECHAR, 's') || *NextChar == LITERAL(WIDECHAR, 'c'))
179 {
180 NewFormat[NewIndex++] = LITERAL(WIDECHAR, 'l');
181 NewFormat[NewIndex] = *NextChar;
182 }
183 else if (*NextChar == LITERAL(WIDECHAR, 'S'))
184 {
185 NewFormat[NewIndex] = LITERAL(WIDECHAR, 's');
186 }
187 else
188 {
189 NewFormat[NewIndex] = *NextChar;
190 }
191
192 OldFormat = NextChar;
193 }
194 }
195 else
196 {
197 NewFormat[NewIndex] = *OldFormat;
198 }
199 }
200 NewFormat[NewIndex] = 0;
201 int32 Result = vswprintf( Dest, DestSize, NewFormat, ArgPtr);
202#else
203 int32 Result = vswprintf( Dest, DestSize, Fmt, ArgPtr);
204#endif
205 va_end( ArgPtr );
206 return Result;
207 }
208#else // PLATFORM_USE_SYSTEM_VSWPRINTF
209 static int32 GetVarArgs( WIDECHAR* Dest, SIZE_T DestSize, const WIDECHAR*& Fmt, va_list ArgPtr );
210#endif // PLATFORM_USE_SYSTEM_VSWPRINTF
211
212 /**
213 * Ansi implementation
214 **/
215 static FORCEINLINE ANSICHAR* Strcpy(ANSICHAR* Dest, SIZE_T DestCount, const ANSICHAR* Src)
216 {
217// Skip suggestions about using strcpy_s instead.
218PRAGMA_DISABLE_DEPRECATION_WARNINGS
219 return strcpy( Dest, Src );
220PRAGMA_ENABLE_DEPRECATION_WARNINGS
221 }
222
223 static FORCEINLINE ANSICHAR* Strncpy(ANSICHAR* Dest, const ANSICHAR* Src, SIZE_T MaxLen)
224 {
225// Skip suggestions about using strncpy_s instead.
226PRAGMA_DISABLE_DEPRECATION_WARNINGS
227 ::strncpy(Dest, Src, MaxLen);
228PRAGMA_ENABLE_DEPRECATION_WARNINGS
229 Dest[MaxLen-1]=0;
230 return Dest;
231 }
232
233 static FORCEINLINE ANSICHAR* Strcat(ANSICHAR* Dest, SIZE_T DestCount, const ANSICHAR* Src)
234 {
235// Skip suggestions about using strcat_s instead.
236PRAGMA_DISABLE_DEPRECATION_WARNINGS
237 return strcat( Dest, Src );
238PRAGMA_ENABLE_DEPRECATION_WARNINGS
239 }
240
241 static FORCEINLINE int32 Strcmp( const ANSICHAR* String1, const ANSICHAR* String2 )
242 {
243 return strcmp(String1, String2);
244 }
245
246 static FORCEINLINE int32 Strncmp( const ANSICHAR* String1, const ANSICHAR* String2, SIZE_T Count )
247 {
248 return strncmp( String1, String2, Count );
249 }
250
251 static FORCEINLINE int32 Strlen( const ANSICHAR* String )
252 {
253 return (int32)strlen( String );
254 }
255
256 static FORCEINLINE int32 Strnlen( const ANSICHAR* String, SIZE_T StringSize )
257 {
258 return (int32)strnlen_s( String, StringSize );
259 }
260
261 static FORCEINLINE const ANSICHAR* Strstr( const ANSICHAR* String, const ANSICHAR* Find)
262 {
263 return strstr(String, Find);
264 }
265
266 static FORCEINLINE const ANSICHAR* Strchr( const ANSICHAR* String, ANSICHAR C)
267 {
268 return strchr(String, C);
269 }
270
271 static FORCEINLINE const ANSICHAR* Strrchr( const ANSICHAR* String, ANSICHAR C)
272 {
273 return strrchr(String, C);
274 }
275
276 static FORCEINLINE int32 Atoi(const ANSICHAR* String)
277 {
278 return atoi( String );
279 }
280
281 static FORCEINLINE int64 Atoi64(const ANSICHAR* String)
282 {
283 return strtoll( String, NULL, 10 );
284 }
285
286 static FORCEINLINE float Atof(const ANSICHAR* String)
287 {
288 return (float)atof( String );
289 }
290
291 static FORCEINLINE double Atod(const ANSICHAR* String)
292 {
293 return atof( String );
294 }
295
296 static FORCEINLINE int32 Strtoi( const ANSICHAR* Start, ANSICHAR** End, int32 Base )
297 {
298 return (int32)strtol( Start, End, Base );
299 }
300
301 static FORCEINLINE int64 Strtoi64( const ANSICHAR* Start, ANSICHAR** End, int32 Base )
302 {
303 return strtoll(Start, End, Base);
304 }
305
306 static FORCEINLINE uint64 Strtoui64( const ANSICHAR* Start, ANSICHAR** End, int32 Base )
307 {
308 return strtoull(Start, End, Base);
309 }
310
311 static FORCEINLINE ANSICHAR* Strtok(ANSICHAR* StrToken, const ANSICHAR* Delim, ANSICHAR** Context)
312 {
313// Skip suggestions about using strtok_s instead.
314PRAGMA_DISABLE_DEPRECATION_WARNINGS
315 return strtok(StrToken, Delim);
316PRAGMA_ENABLE_DEPRECATION_WARNINGS
317 }
318
319 static int32 GetVarArgs( ANSICHAR* Dest, SIZE_T DestSize, const ANSICHAR*& Fmt, va_list ArgPtr )
320 {
321 int32 Result = vsnprintf(Dest, DestSize, Fmt, ArgPtr);
322 va_end( ArgPtr );
323 return (Result != -1 && Result < (int32)DestSize) ? Result : -1;
324 }
325
326 /**
327 * UTF8CHAR implementation.
328 */
329 static FORCEINLINE UTF8CHAR* Strcpy(UTF8CHAR* Dest, SIZE_T DestCount, const UTF8CHAR* Src)
330 {
331 return (UTF8CHAR*)Strcpy((ANSICHAR*)Dest, DestCount, (const ANSICHAR*)Src);
332 }
333
334 static FORCEINLINE UTF8CHAR* Strncpy(UTF8CHAR* Dest, const UTF8CHAR* Src, SIZE_T MaxLen)
335 {
336 return (UTF8CHAR*)Strncpy((ANSICHAR*)Dest, (const ANSICHAR*)Src, MaxLen);
337 }
338
339 static FORCEINLINE UTF8CHAR* Strcat(UTF8CHAR* Dest, SIZE_T DestCount, const UTF8CHAR* Src)
340 {
341 return (UTF8CHAR*)Strcat((ANSICHAR*)Dest, DestCount, (const ANSICHAR*)Src);
342 }
343
344 static FORCEINLINE int32 Strcmp(const UTF8CHAR* String1, const UTF8CHAR* String2)
345 {
346 return Strcmp((const ANSICHAR*)String1, (const ANSICHAR*)String2);
347 }
348
349 static FORCEINLINE int32 Strncmp(const UTF8CHAR* String1, const UTF8CHAR* String2, SIZE_T Count)
350 {
351 return Strncmp((const ANSICHAR*)String1, (const ANSICHAR*)String2, Count);
352 }
353
354 static FORCEINLINE int32 Strlen(const UTF8CHAR* String)
355 {
356 return Strlen((const ANSICHAR*)String);
357 }
358
359 static FORCEINLINE int32 Strnlen(const UTF8CHAR* String, SIZE_T StringSize)
360 {
361 return Strnlen((const ANSICHAR*)String, StringSize);
362 }
363
364 static FORCEINLINE const UTF8CHAR* Strstr(const UTF8CHAR* String, const UTF8CHAR* Find)
365 {
366 return (const UTF8CHAR*)Strstr((const ANSICHAR*)String, (const ANSICHAR*)Find);
367 }
368
369 static FORCEINLINE const UTF8CHAR* Strchr(const UTF8CHAR* String, UTF8CHAR C)
370 {
371 return (const UTF8CHAR*)Strchr((const ANSICHAR*)String, (ANSICHAR)C);
372 }
373
374 static FORCEINLINE const UTF8CHAR* Strrchr(const UTF8CHAR* String, UTF8CHAR C)
375 {
376 return (const UTF8CHAR*)Strrchr((const ANSICHAR*)String, (ANSICHAR)C);
377 }
378
379 static FORCEINLINE int32 Atoi(const UTF8CHAR* String)
380 {
381 return Atoi((const ANSICHAR*)String);
382 }
383
384 static FORCEINLINE int64 Atoi64(const UTF8CHAR* String)
385 {
386 return Atoi64((const ANSICHAR*)String);
387 }
388
389 static FORCEINLINE float Atof(const UTF8CHAR* String)
390 {
391 return Atof((const ANSICHAR*)String);
392 }
393
394 static FORCEINLINE double Atod(const UTF8CHAR* String)
395 {
396 return Atod((const ANSICHAR*)String);
397 }
398
399 static FORCEINLINE int32 Strtoi(const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
400 {
401 return Strtoi((const ANSICHAR*)Start, (ANSICHAR**)End, Base);
402 }
403
404 static FORCEINLINE int64 Strtoi64(const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
405 {
406 return Strtoi64((const ANSICHAR*)Start, (ANSICHAR**)End, Base);
407 }
408
409 static FORCEINLINE uint64 Strtoui64(const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
410 {
411 return Strtoui64((const ANSICHAR*)Start, (ANSICHAR**)End, Base);
412 }
413
414 static FORCEINLINE UTF8CHAR* Strtok(UTF8CHAR* StrToken, const UTF8CHAR* Delim, UTF8CHAR** Context)
415 {
416 return (UTF8CHAR*)Strtok((ANSICHAR*)StrToken, (const ANSICHAR*)Delim, (ANSICHAR**)Context);
417 }
418
419 static FORCEINLINE int32 GetVarArgs(UTF8CHAR* Dest, SIZE_T DestSize, const UTF8CHAR*& Fmt, va_list ArgPtr)
420 {
421 return GetVarArgs((ANSICHAR*)Dest, DestSize, *(const ANSICHAR**)&Fmt, ArgPtr);
422 }
423
424 /**
425 * UCS2 implementation
426 **/
427
428 static FORCEINLINE int32 Strlen( const UCS2CHAR* String )
429 {
430 int32 Result = 0;
431 while (*String++)
432 {
433 ++Result;
434 }
435
436 return Result;
437 }
438
439 static FORCEINLINE int32 Strnlen( const UCS2CHAR* String, SIZE_T StringSize )
440 {
441 int32 Result = 0;
442 while (StringSize-- > 0 && *String++)
443 {
444 ++Result;
445 }
446
447 return Result;
448 }
449};
450
451#endif
#define PLATFORM_USE_GENERIC_STRING_IMPLEMENTATION
Definition Platform.h:529
#define PLATFORM_TCHAR_IS_CHAR16
Definition Platform.h:260