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