Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
MicrosoftPlatformString.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5// HEADER_UNIT_SKIP - Included through other header
6
7#include "Misc/Char.h"
9 #include "GenericPlatform/GenericWidePlatformString.h"
10#else
11 #include "GenericPlatform/GenericPlatformString.h"
12#endif
13#include "GenericPlatform/GenericPlatformStricmp.h"
14#include <stdarg.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18#include <tchar.h>
19
20/**
21* Microsoft specific implementation
22**/
23
24#pragma warning(push)
25#pragma warning(disable : 4996) // 'function' was declared deprecated (needed for the secure string functions)
26#pragma warning(disable : 4995) // 'function' was declared deprecated (needed for the secure string functions)
27
31#else
33#endif
34{
37#else
39#endif
40
41 using FGenericPlatformString::Stricmp;
42 using FGenericPlatformString::Strncmp;
43 using FGenericPlatformString::Strnicmp;
44
45 /**
46 * Wide character implementation
47 **/
48 static FORCEINLINE WIDECHAR* Strcpy(WIDECHAR* Dest, SIZE_T DestCount, const WIDECHAR* Src)
49 {
50 return (WIDECHAR*)_tcscpy(Dest, Src);
51 }
52
53 static FORCEINLINE WIDECHAR* Strncpy(WIDECHAR* Dest, const WIDECHAR* Src, SIZE_T MaxLen)
54 {
55 _tcsncpy(Dest, Src, MaxLen-1);
56 Dest[MaxLen-1] = 0;
57 return Dest;
58 }
59
60 static FORCEINLINE WIDECHAR* Strcat(WIDECHAR* Dest, SIZE_T DestCount, const WIDECHAR* Src)
61 {
62 return (WIDECHAR*)_tcscat(Dest, Src);
63 }
64
65 static FORCEINLINE WIDECHAR* Strupr(WIDECHAR* Dest, SIZE_T DestCount)
66 {
67 return (WIDECHAR*)_tcsupr(Dest);
68 }
69
70 static FORCEINLINE int32 Strcmp( const WIDECHAR* String1, const WIDECHAR* String2 )
71 {
72 return _tcscmp(String1, String2);
73 }
74
75 static FORCEINLINE int32 Strncmp( const WIDECHAR* String1, const WIDECHAR* String2, SIZE_T Count )
76 {
77 return _tcsncmp( String1, String2, Count );
78 }
79
80 static FORCEINLINE int32 Strlen( const WIDECHAR* String )
81 {
82 return _tcslen( String );
83 }
84
85 static FORCEINLINE int32 Strnlen( const WIDECHAR* String, SIZE_T StringSize )
86 {
87 return _tcsnlen( String, StringSize );
88 }
89
90 static FORCEINLINE const WIDECHAR* Strstr( const WIDECHAR* String, const WIDECHAR* Find)
91 {
92 return _tcsstr( String, Find );
93 }
94
95 static FORCEINLINE const WIDECHAR* Strchr( const WIDECHAR* String, WIDECHAR C)
96 {
97 return _tcschr( String, C );
98 }
99
100 static FORCEINLINE const WIDECHAR* Strrchr( const WIDECHAR* String, WIDECHAR C)
101 {
102 return _tcsrchr( String, C );
103 }
104
105 static FORCEINLINE int32 Atoi(const WIDECHAR* String)
106 {
107 return _tstoi( String );
108 }
109
110 static FORCEINLINE int64 Atoi64(const WIDECHAR* String)
111 {
112 return _tstoi64( String );
113 }
114
115 static FORCEINLINE float Atof(const WIDECHAR* String)
116 {
117 return (float)_tstof( String );
118 }
119
120 static FORCEINLINE double Atod(const WIDECHAR* String)
121 {
122 return _tcstod( String, NULL );
123 }
124
125 static FORCEINLINE int32 Strtoi( const WIDECHAR* Start, WIDECHAR** End, int32 Base )
126 {
127 return _tcstoul( Start, End, Base );
128 }
129
130 static FORCEINLINE int64 Strtoi64( const WIDECHAR* Start, WIDECHAR** End, int32 Base )
131 {
132 return _tcstoi64( Start, End, Base );
133 }
134
135 static FORCEINLINE uint64 Strtoui64( const WIDECHAR* Start, WIDECHAR** End, int32 Base )
136 {
137 return _tcstoui64( Start, End, Base );
138 }
139
140 static FORCEINLINE WIDECHAR* Strtok(WIDECHAR* StrToken, const WIDECHAR* Delim, WIDECHAR** Context)
141 {
142 return _tcstok_s(StrToken, Delim, Context);
143 }
144
145// Allow fallback to FGenericWidePlatformString::GetVarArgs when PLATFORM_USE_GENERIC_STRING_IMPLEMENTATION is set.
147 using Super::GetVarArgs;
148#else
149 static FORCEINLINE int32 GetVarArgs( WIDECHAR* Dest, SIZE_T DestSize, const WIDECHAR*& Fmt, va_list ArgPtr )
150 {
151 int32 Result = vswprintf(Dest, DestSize, Fmt, ArgPtr);
152 va_end( ArgPtr );
153 return Result;
154 }
155#endif
156
157 /**
158 * Ansi implementation
159 **/
160 static FORCEINLINE ANSICHAR* Strcpy(ANSICHAR* Dest, SIZE_T DestCount, const ANSICHAR* Src)
161 {
162 return (ANSICHAR*)strcpy(Dest, Src);
163 }
164
165 static FORCEINLINE ANSICHAR* Strncpy(ANSICHAR* Dest, const ANSICHAR* Src, SIZE_T MaxLen)
166 {
167 strncpy(Dest, Src, MaxLen);
168 Dest[MaxLen-1] = 0;
169 return Dest;
170 }
171
172 static FORCEINLINE ANSICHAR* Strcat(ANSICHAR* Dest, SIZE_T DestCount, const ANSICHAR* Src)
173 {
174 return (ANSICHAR*)strcat( Dest, Src );
175 }
176
177 static FORCEINLINE ANSICHAR* Strupr(ANSICHAR* Dest, SIZE_T DestCount)
178 {
179 return (ANSICHAR*)_strupr(Dest);
180 }
181
182 static FORCEINLINE int32 Strcmp( const ANSICHAR* String1, const ANSICHAR* String2 )
183 {
184 return strcmp(String1, String2);
185 }
186
187 static FORCEINLINE int32 Strncmp( const ANSICHAR* String1, const ANSICHAR* String2, SIZE_T Count )
188 {
189 return strncmp( String1, String2, Count );
190 }
191
192 static FORCEINLINE int32 Strlen( const ANSICHAR* String )
193 {
194 return strlen( String );
195 }
196
197 static FORCEINLINE int32 Strnlen( const ANSICHAR* String, SIZE_T StringSize )
198 {
199 return strnlen( String, StringSize );
200 }
201
202 static FORCEINLINE const ANSICHAR* Strstr( const ANSICHAR* String, const ANSICHAR* Find)
203 {
204 return strstr(String, Find);
205 }
206
207 static FORCEINLINE const ANSICHAR* Strchr( const ANSICHAR* String, ANSICHAR C)
208 {
209 return strchr(String, C);
210 }
211
212 static FORCEINLINE const ANSICHAR* Strrchr( const ANSICHAR* String, ANSICHAR C)
213 {
214 return strrchr(String, C);
215 }
216
217 static FORCEINLINE int32 Atoi(const ANSICHAR* String)
218 {
219 return atoi( String );
220 }
221
222 static FORCEINLINE int64 Atoi64(const ANSICHAR* String)
223 {
224 return _strtoi64( String, NULL, 10 );
225 }
226
227 static FORCEINLINE float Atof(const ANSICHAR* String)
228 {
229 return (float)atof( String );
230 }
231
232 static FORCEINLINE double Atod(const ANSICHAR* String)
233 {
234 return atof( String );
235 }
236
237 static FORCEINLINE int32 Strtoi( const ANSICHAR* Start, ANSICHAR** End, int32 Base )
238 {
239 return strtol( Start, End, Base );
240 }
241
242 static FORCEINLINE int64 Strtoi64( const ANSICHAR* Start, ANSICHAR** End, int32 Base )
243 {
244 return _strtoi64( Start, End, Base );
245 }
246
247 static FORCEINLINE uint64 Strtoui64( const ANSICHAR* Start, ANSICHAR** End, int32 Base )
248 {
249 return _strtoui64( Start, End, Base );
250 }
251
252 static FORCEINLINE ANSICHAR* Strtok(ANSICHAR* StrToken, const ANSICHAR* Delim, ANSICHAR** Context)
253 {
254 return strtok_s(StrToken, Delim, Context);
255 }
256
257 static FORCEINLINE int32 GetVarArgs( ANSICHAR* Dest, SIZE_T DestSize, const ANSICHAR*& Fmt, va_list ArgPtr )
258 {
259 int32 Result = vsnprintf( Dest, DestSize, Fmt, ArgPtr );
260 va_end( ArgPtr );
261 return (Result != -1 && Result < (int32)DestSize) ? Result : -1;
262 }
263
264 /**
265 * UCS2CHAR implementation - this is identical to WIDECHAR for Windows platforms
266 */
267
268 static FORCEINLINE int32 Strlen( const UCS2CHAR* String )
269 {
270 return _tcslen( (const WIDECHAR*)String );
271 }
272
273 static FORCEINLINE int32 Strnlen( const UCS2CHAR* String, SIZE_T StringSize )
274 {
275 return _tcsnlen( (const WIDECHAR*)String, StringSize );
276 }
277
278 /**
279 * UTF8CHAR implementation.
280 */
281 static FORCEINLINE UTF8CHAR* Strcpy(UTF8CHAR* Dest, SIZE_T DestCount, const UTF8CHAR* Src)
282 {
283 return (UTF8CHAR*)Strcpy((ANSICHAR*)Dest, DestCount, (const ANSICHAR*)Src);
284 }
285
286 static FORCEINLINE UTF8CHAR* Strncpy(UTF8CHAR* Dest, const UTF8CHAR* Src, SIZE_T MaxLen)
287 {
288 return (UTF8CHAR*)Strncpy((ANSICHAR*)Dest, (const ANSICHAR*)Src, MaxLen);
289 }
290
291 static FORCEINLINE UTF8CHAR* Strcat(UTF8CHAR* Dest, SIZE_T DestCount, const UTF8CHAR* Src)
292 {
293 return (UTF8CHAR*)Strcat((ANSICHAR*)Dest, DestCount, (const ANSICHAR*)Src);
294 }
295
296 static FORCEINLINE UTF8CHAR* Strupr(UTF8CHAR* Dest, SIZE_T DestCount)
297 {
298 return (UTF8CHAR*)Strupr((ANSICHAR*)Dest, DestCount);
299 }
300
301 static FORCEINLINE int32 Strcmp(const UTF8CHAR* String1, const UTF8CHAR* String2)
302 {
303 return Strcmp((const ANSICHAR*)String1, (const ANSICHAR*)String2);
304 }
305
306 static FORCEINLINE int32 Strncmp(const UTF8CHAR* String1, const UTF8CHAR* String2, SIZE_T Count)
307 {
308 return Strncmp((const ANSICHAR*)String1, (const ANSICHAR*)String2, Count);
309 }
310
311 static FORCEINLINE int32 Strlen(const UTF8CHAR* String)
312 {
313 return Strlen((const ANSICHAR*)String);
314 }
315
316 static FORCEINLINE int32 Strnlen(const UTF8CHAR* String, SIZE_T StringSize)
317 {
318 return Strnlen((const ANSICHAR*)String, StringSize);
319 }
320
321 static FORCEINLINE const UTF8CHAR* Strstr(const UTF8CHAR* String, const UTF8CHAR* Find)
322 {
323 return (const UTF8CHAR*)Strstr((const ANSICHAR*)String, (const ANSICHAR*)Find);
324 }
325
326 static FORCEINLINE const UTF8CHAR* Strchr(const UTF8CHAR* String, UTF8CHAR C)
327 {
328 return (const UTF8CHAR*)Strchr((const ANSICHAR*)String, (ANSICHAR)C);
329 }
330
331 static FORCEINLINE const UTF8CHAR* Strrchr(const UTF8CHAR* String, UTF8CHAR C)
332 {
333 return (const UTF8CHAR*)Strrchr((const ANSICHAR*)String, (ANSICHAR)C);
334 }
335
336 static FORCEINLINE int32 Atoi(const UTF8CHAR* String)
337 {
338 return Atoi((const ANSICHAR*)String);
339 }
340
341 static FORCEINLINE int64 Atoi64(const UTF8CHAR* String)
342 {
343 return Atoi64((const ANSICHAR*)String);
344 }
345
346 static FORCEINLINE float Atof(const UTF8CHAR* String)
347 {
348 return Atof((const ANSICHAR*)String);
349 }
350
351 static FORCEINLINE double Atod(const UTF8CHAR* String)
352 {
353 return Atod((const ANSICHAR*)String);
354 }
355
356 static FORCEINLINE int32 Strtoi(const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
357 {
358 return Strtoi((const ANSICHAR*)Start, (ANSICHAR**)End, Base);
359 }
360
361 static FORCEINLINE int64 Strtoi64(const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
362 {
363 return Strtoi64((const ANSICHAR*)Start, (ANSICHAR**)End, Base);
364 }
365
366 static FORCEINLINE uint64 Strtoui64(const UTF8CHAR* Start, UTF8CHAR** End, int32 Base)
367 {
368 return Strtoui64((const ANSICHAR*)Start, (ANSICHAR**)End, Base);
369 }
370
371 static FORCEINLINE UTF8CHAR* Strtok(UTF8CHAR* StrToken, const UTF8CHAR* Delim, UTF8CHAR** Context)
372 {
373 return (UTF8CHAR*)Strtok((ANSICHAR*)StrToken, (const ANSICHAR*)Delim, (ANSICHAR**)Context);
374 }
375
376 static FORCEINLINE int32 GetVarArgs(UTF8CHAR* Dest, SIZE_T DestSize, const UTF8CHAR*& Fmt, va_list ArgPtr)
377 {
378 return GetVarArgs((ANSICHAR*)Dest, DestSize, *(const ANSICHAR**)&Fmt, ArgPtr);
379 }
380};
381
382#pragma warning(pop) // 'function' was was declared deprecated (needed for the secure string functions)
FPlatformTypes::CHAR16 UCS2CHAR
A 16-bit character containing a UCS2 (Unicode, 16-bit, fixed-width) code unit, used for compatibility...
Definition Platform.h:975
#define PLATFORM_USE_GENERIC_STRING_IMPLEMENTATION
Definition Platform.h:529
#define FORCEINLINE
Definition Platform.h:644
static FORCEINLINE int64 Atoi64(const WIDECHAR *String)
static FORCEINLINE int32 Strtoi(const WIDECHAR *Start, WIDECHAR **End, int32 Base)
static FORCEINLINE uint64 Strtoui64(const UTF8CHAR *Start, UTF8CHAR **End, int32 Base)
static FORCEINLINE int32 Strcmp(const ANSICHAR *String1, const ANSICHAR *String2)
static FORCEINLINE int32 Strcmp(const WIDECHAR *String1, const WIDECHAR *String2)
static FORCEINLINE int32 Strlen(const UCS2CHAR *String)
static FORCEINLINE const UTF8CHAR * Strstr(const UTF8CHAR *String, const UTF8CHAR *Find)
static FORCEINLINE int64 Strtoi64(const ANSICHAR *Start, ANSICHAR **End, int32 Base)
static FORCEINLINE const ANSICHAR * Strstr(const ANSICHAR *String, const ANSICHAR *Find)
static FORCEINLINE const ANSICHAR * Strrchr(const ANSICHAR *String, ANSICHAR C)
static FORCEINLINE const ANSICHAR * Strchr(const ANSICHAR *String, ANSICHAR C)
static FORCEINLINE WIDECHAR * Strcpy(WIDECHAR *Dest, SIZE_T DestCount, const WIDECHAR *Src)
static FORCEINLINE int32 Atoi(const ANSICHAR *String)
static FORCEINLINE int32 Strncmp(const ANSICHAR *String1, const ANSICHAR *String2, SIZE_T Count)
static FORCEINLINE UTF8CHAR * Strtok(UTF8CHAR *StrToken, const UTF8CHAR *Delim, UTF8CHAR **Context)
static FORCEINLINE WIDECHAR * Strncpy(WIDECHAR *Dest, const WIDECHAR *Src, SIZE_T MaxLen)
static FORCEINLINE const WIDECHAR * Strchr(const WIDECHAR *String, WIDECHAR C)
static FORCEINLINE const WIDECHAR * Strstr(const WIDECHAR *String, const WIDECHAR *Find)
static FORCEINLINE ANSICHAR * Strupr(ANSICHAR *Dest, SIZE_T DestCount)
static FORCEINLINE int32 Strlen(const ANSICHAR *String)
static FORCEINLINE int64 Atoi64(const ANSICHAR *String)
static FORCEINLINE uint64 Strtoui64(const ANSICHAR *Start, ANSICHAR **End, int32 Base)
static FORCEINLINE int32 Strlen(const WIDECHAR *String)
static FORCEINLINE int32 Strcmp(const UTF8CHAR *String1, const UTF8CHAR *String2)
static FORCEINLINE int32 GetVarArgs(ANSICHAR *Dest, SIZE_T DestSize, const ANSICHAR *&Fmt, va_list ArgPtr)
static FORCEINLINE int64 Atoi64(const UTF8CHAR *String)
static FORCEINLINE UTF8CHAR * Strupr(UTF8CHAR *Dest, SIZE_T DestCount)
static FORCEINLINE const UTF8CHAR * Strchr(const UTF8CHAR *String, UTF8CHAR C)
static FORCEINLINE int32 Strnlen(const WIDECHAR *String, SIZE_T StringSize)
static FORCEINLINE int32 Strnlen(const ANSICHAR *String, SIZE_T StringSize)
static FORCEINLINE double Atod(const WIDECHAR *String)
static FORCEINLINE int64 Strtoi64(const WIDECHAR *Start, WIDECHAR **End, int32 Base)
static FORCEINLINE const UTF8CHAR * Strrchr(const UTF8CHAR *String, UTF8CHAR C)
static FORCEINLINE WIDECHAR * Strtok(WIDECHAR *StrToken, const WIDECHAR *Delim, WIDECHAR **Context)
static FORCEINLINE int32 Atoi(const WIDECHAR *String)
static FORCEINLINE int32 Strnlen(const UTF8CHAR *String, SIZE_T StringSize)
static FORCEINLINE int32 GetVarArgs(UTF8CHAR *Dest, SIZE_T DestSize, const UTF8CHAR *&Fmt, va_list ArgPtr)
static FORCEINLINE UTF8CHAR * Strcpy(UTF8CHAR *Dest, SIZE_T DestCount, const UTF8CHAR *Src)
static FORCEINLINE int32 Strnlen(const UCS2CHAR *String, SIZE_T StringSize)
static FORCEINLINE UTF8CHAR * Strncpy(UTF8CHAR *Dest, const UTF8CHAR *Src, SIZE_T MaxLen)
static FORCEINLINE float Atof(const WIDECHAR *String)
static FORCEINLINE WIDECHAR * Strupr(WIDECHAR *Dest, SIZE_T DestCount)
static FORCEINLINE float Atof(const UTF8CHAR *String)
static FORCEINLINE WIDECHAR * Strcat(WIDECHAR *Dest, SIZE_T DestCount, const WIDECHAR *Src)
static FORCEINLINE int32 Strtoi(const UTF8CHAR *Start, UTF8CHAR **End, int32 Base)
static FORCEINLINE int32 Atoi(const UTF8CHAR *String)
static FORCEINLINE UTF8CHAR * Strcat(UTF8CHAR *Dest, SIZE_T DestCount, const UTF8CHAR *Src)
static FORCEINLINE const WIDECHAR * Strrchr(const WIDECHAR *String, WIDECHAR C)
static FORCEINLINE int32 Strtoi(const ANSICHAR *Start, ANSICHAR **End, int32 Base)
static FORCEINLINE double Atod(const UTF8CHAR *String)
static FORCEINLINE int64 Strtoi64(const UTF8CHAR *Start, UTF8CHAR **End, int32 Base)
static FORCEINLINE ANSICHAR * Strcat(ANSICHAR *Dest, SIZE_T DestCount, const ANSICHAR *Src)
static FORCEINLINE ANSICHAR * Strtok(ANSICHAR *StrToken, const ANSICHAR *Delim, ANSICHAR **Context)
static FORCEINLINE uint64 Strtoui64(const WIDECHAR *Start, WIDECHAR **End, int32 Base)
static FORCEINLINE int32 Strncmp(const UTF8CHAR *String1, const UTF8CHAR *String2, SIZE_T Count)
static FORCEINLINE ANSICHAR * Strncpy(ANSICHAR *Dest, const ANSICHAR *Src, SIZE_T MaxLen)
static FORCEINLINE int32 Strncmp(const WIDECHAR *String1, const WIDECHAR *String2, SIZE_T Count)
static FORCEINLINE int32 GetVarArgs(WIDECHAR *Dest, SIZE_T DestSize, const WIDECHAR *&Fmt, va_list ArgPtr)
static FORCEINLINE int32 Strlen(const UTF8CHAR *String)
static FORCEINLINE float Atof(const ANSICHAR *String)
static FORCEINLINE double Atod(const ANSICHAR *String)
static FORCEINLINE ANSICHAR * Strcpy(ANSICHAR *Dest, SIZE_T DestCount, const ANSICHAR *Src)