Torque3D Documentation / _generateds / stringFunctions.h

stringFunctions.h

Engine/source/core/strings/stringFunctions.h

More...

Public Defines

define
dStrdup(x) (x, __FILE__, __LINE__)

Public Functions

bool
dAtob(const char * str)
dAtod(const char * str)
dAtof(const char * str)
dAtoi(const char * str)
dAtoui(const char * str, U32 base)
dAtous(const char * str, U32 base)
bool
dIsalnum(const char c)
bool
dIsalpha(const char c)
bool
dIsdigit(const char c)
bool
dIsquote(const char c)
bool
dIsspace(const char c)
int
dItoa(int n, char s)
dPrintf(const char * format, ... )
dSprintf(char * buffer, U32 bufferSize, const char * format, ... )
dSscanf(const char * buffer, const char * format, ... )
char *
dStrcat(char * dst, const char * src, dsize_t dstSize)

Concatenate strings.

char *
dStrcatl(char * dst, dsize_t dstSize, ... )
char *
dStrchr(char * str, S32 c)
const char *
dStrchr(const char * str, S32 c)
dStrcmp(const char * str1, const char * str2)
dStrcmp(const UTF16 * str1, const UTF16 * str2)
char *
dStrcpy(char * dst, const char * src, dsize_t dstSize)
char *
dStrcpyl(char * dst, dsize_t dstSize, ... )
dStrcspn(const char * str, const char * set)
char *
dStrdup_r(const char * src, const char * fileName, dsize_t lineNumber)
bool
dStrEndsWith(const char * str1, const char * str2)

Check if one string ends with another.

bool
dStrEqual(const char * str1, const char * str2)

Safe form of dStrcmp: checks both strings for NULL before comparing.

char *
dStrichr(char * str, char ch)
const char *
dStrichr(const char * str, char ch)
dStricmp(const char * str1, const char * str2)
char *
dStripPath(const char * filename)

Strip the path from the input filename.

bool
dStrIsEmpty(const char * src)
char *
dStristr(char * str1, const char * str2)
const char *
dStristr(const char * str1, const char * str2)
dStrlcat(char * dst, const char * src, dsize_t dstSize)
dStrlcpy(char * dst, const char * src, dsize_t dstSize)
dStrlen(const char * str)
char *
dStrlwr(char * str)
dStrnatcasecmp(const char * str1, const char * str2)
dStrnatcmp(const char * str1, const char * str2)
char *
dStrncat(char * dst, const char * src, dsize_t len)
dStrncmp(const char * str1, const char * str2, dsize_t len)
char *
dStrncpy(char * dst, const char * src, dsize_t len)
dStrnicmp(const char * str1, const char * str2, dsize_t len)
char *
dStrrchr(char * str, S32 c)
const char *
dStrrchr(const char * str, S32 c)
int
dStrrev(char * str)
dStrspn(const char * str, const char * set)
bool
dStrStartsWith(const char * str1, const char * str2)

Check if one string starts with another.

char *
dStrstr(const char * str1, const char * str2)
char *
dStrtok(char * str, const char * sep)
char *
dStrupr(char * str)
char
dTolower(const char c)
char
dToupper(const char c)
dVprintf(const char * format, va_list arglist)
dVsprintf(char * buffer, U32 bufferSize, const char * format, va_list arglist)

Detailed Description

Public Defines

dStrdup(x) (x, __FILE__, __LINE__)

Public Functions

dAtob(const char * str)

dAtod(const char * str)

dAtof(const char * str)

dAtoi(const char * str)

dAtoui(const char * str, U32 base)

dAtous(const char * str, U32 base)

dIsalnum(const char c)

dIsalpha(const char c)

dIsdigit(const char c)

dIsquote(const char c)

dIsspace(const char c)

dItoa(int n, char s)

dPrintf(const char * format, ... )

dSprintf(char * buffer, U32 bufferSize, const char * format, ... )

dSscanf(const char * buffer, const char * format, ... )

dStrcat(char * dst, const char * src, dsize_t dstSize)

Concatenate strings.

note:

The third parameter is the size of the destination buffer like strlcat instead of the number of characters to copy like strncat. This is done under the assumption that being easier to use will make this safer. If you want the original behavior use dStrncat.

dStrcatl(char * dst, dsize_t dstSize, ... )

dStrchr(char * str, S32 c)

dStrchr(const char * str, S32 c)

dStrcmp(const char * str1, const char * str2)

dStrcmp(const UTF16 * str1, const UTF16 * str2)

dStrcpy(char * dst, const char * src, dsize_t dstSize)

dStrcpyl(char * dst, dsize_t dstSize, ... )

dStrcspn(const char * str, const char * set)

dStrdup_r(const char * src, const char * fileName, dsize_t lineNumber)

dStrEndsWith(const char * str1, const char * str2)

Check if one string ends with another.

dStrEqual(const char * str1, const char * str2)

Safe form of dStrcmp: checks both strings for NULL before comparing.

dStrichr(char * str, char ch)

dStrichr(const char * str, char ch)

dStricmp(const char * str1, const char * str2)

dStripPath(const char * filename)

Strip the path from the input filename.

dStrIsEmpty(const char * src)

dStristr(char * str1, const char * str2)

dStristr(const char * str1, const char * str2)

dStrlcat(char * dst, const char * src, dsize_t dstSize)

dStrlcpy(char * dst, const char * src, dsize_t dstSize)

dStrlen(const char * str)

dStrlwr(char * str)

dStrnatcasecmp(const char * str1, const char * str2)

dStrnatcmp(const char * str1, const char * str2)

dStrncat(char * dst, const char * src, dsize_t len)

dStrncmp(const char * str1, const char * str2, dsize_t len)

dStrncpy(char * dst, const char * src, dsize_t len)

dStrnicmp(const char * str1, const char * str2, dsize_t len)

dStrrchr(char * str, S32 c)

dStrrchr(const char * str, S32 c)

dStrrev(char * str)

dStrspn(const char * str, const char * set)

dStrStartsWith(const char * str1, const char * str2)

Check if one string starts with another.

dStrstr(const char * str1, const char * str2)

dStrtok(char * str, const char * sep)

dStrupr(char * str)

dTolower(const char c)

dToupper(const char c)

dVprintf(const char * format, va_list arglist)

dVsprintf(char * buffer, U32 bufferSize, const char * format, va_list arglist)

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _STRINGFUNCTIONS_H_
 25#define _STRINGFUNCTIONS_H_
 26
 27#include <stdlib.h>
 28#include <string.h>
 29#include <ctype.h>
 30#include <cstdarg>
 31
 32#ifndef _TORQUE_TYPES_H_
 33#include "platform/types.h"
 34#endif
 35
 36#ifndef _PLATFORMASSERT_H_
 37#include "platform/platformAssert.h"
 38#endif
 39
 40#if defined(TORQUE_OS_WIN)
 41// These standard functions are not defined on Win32 and other Microsoft platforms...
 42#define strcasecmp   _stricmp
 43#define strncasecmp  _strnicmp
 44
 45#if _MSC_VER < 1800
 46#define strtof       (float)strtod
 47#endif // _MSC_VER < 1800
 48
 49#endif // defined(TORQUE_OS_WIN)
 50
 51//------------------------------------------------------------------------------
 52// standard string functions [defined in platformString.cpp]
 53
 54// Buffer size bounds checking "safe" versions of strcat and strcpy. Ideally you
 55// should use these and check if they return >= dstSize and throw an error if so.
 56extern S32  dStrlcat(char *dst, const char *src, dsize_t dstSize);
 57extern S32  dStrlcpy(char *dst, const char *src, dsize_t dstSize);
 58
 59#ifdef UNSAFE_STRING_FUNCTIONS
 60/// @deprecated Use dStrcat(char *, const char *, dsize_t) instead
 61inline char *dStrcat(char *dst, const char *src)
 62{
 63   AssertFatal(false, "dStrcat without length is deprecated");
 64   return strcat(dst,src);
 65}   
 66#endif
 67
 68/// Concatenate strings.
 69/// @note The third parameter is the size of the destination buffer like strlcat
 70///       instead of the number of characters to copy like strncat. This is done
 71///       under the assumption that being easier to use will make this safer.
 72///       If you want the original behavior use dStrncat.
 73inline char *dStrcat(char *dst, const char *src, dsize_t dstSize)
 74{
 75   dStrlcat(dst, src, dstSize);
 76   return dst;
 77}
 78
 79inline char *dStrncat(char *dst, const char *src, dsize_t len)
 80{
 81   return strncat(dst, src, len);
 82}
 83
 84inline S32  dStrcmp(const char *str1, const char *str2)
 85{
 86   return strcmp(str1, str2);   
 87}
 88
 89inline bool dStrIsEmpty(const char *src)
 90{
 91   return src == 0 || src[0] == '\0';
 92}
 93
 94inline S32  dStrncmp(const char *str1, const char *str2, dsize_t len)
 95{
 96   return strncmp(str1, str2, len);   
 97}  
 98
 99inline S32  dStricmp(const char *str1, const char *str2)
100{
101   return strcasecmp( str1, str2 );
102}
103
104inline S32  dStrnicmp(const char *str1, const char *str2, dsize_t len)
105{
106   return strncasecmp( str1, str2, len );
107}
108
109#ifdef UNSAFE_STRING_FUNCTIONS
110/// @deprecated Use strcpy(char *, const char *, dsize_t) instead
111inline char *dStrcpy(char *dst, const char *src)
112{
113   AssertFatal(false, "dStrcpy without length is deprecated");
114   return strcpy(dst,src);
115}
116#endif
117
118inline char *dStrcpy(char *dst, const char *src, dsize_t dstSize)
119{
120   dStrlcpy(dst, src, dstSize);
121   return dst;
122}   
123
124inline char *dStrncpy(char *dst, const char *src, dsize_t len)
125{
126   return strncpy(dst,src,len);
127}   
128
129inline dsize_t dStrlen(const char *str)
130{
131   return strlen(str);
132}   
133
134inline char *dStrchr(char *str, S32 c)
135{
136   return strchr(str,c);
137}   
138
139inline const char *dStrchr(const char *str, S32 c)
140{
141   return strchr(str,c);
142}   
143
144inline char *dStrrchr(char *str, S32 c)
145{
146   return strrchr(str,c);
147}
148
149inline const char *dStrrchr(const char *str, S32 c)
150{
151   return strrchr(str,c);
152}   
153
154inline dsize_t dStrspn(const char *str, const char *set)
155{
156   return strspn(str, set);
157}
158
159inline dsize_t dStrcspn(const char *str, const char *set)
160{
161   return strcspn(str, set);
162}   
163
164inline char *dStrstr(const char *str1, const char *str2)
165{
166   return strstr((char *)str1,str2);
167}
168
169const char* dStristr( const char* str1, const char* str2 );
170char* dStristr( char* str1, const char* str2 );
171
172
173inline char *dStrtok(char *str, const char *sep)
174{
175   return strtok(str, sep);
176}
177
178
179inline S32 dAtoi(const char *str)
180{
181   return strtol(str, NULL, 10);
182}
183
184inline U32 dAtoui(const char *str, U32 base = 10)
185{
186   return strtoul(str, NULL, base);
187}
188
189inline U16 dAtous(const char *str, U32 base = 10)
190{
191   return strtoul(str, NULL, base);
192}
193
194inline F32 dAtof(const char *str)
195{
196   return strtof(str, NULL);
197}
198
199inline F64 dAtod(const char *str)
200{
201   return strtod(str, NULL);
202}
203
204inline char dToupper(const char c)
205{
206   return toupper( c );
207}
208
209inline char dTolower(const char c)
210{
211   return tolower( c );
212}
213
214inline bool dIsalnum(const char c)
215{
216   return isalnum(c);
217}
218
219inline bool dIsalpha(const char c)
220{
221   return isalpha(c);
222}
223
224inline bool dIsspace(const char c)
225{
226   return isspace(c);
227}
228
229inline bool dIsdigit(const char c)
230{
231   return isdigit(c);
232}
233
234inline bool dIsquote(const char c)
235{
236   return ( c == '\"' );
237}
238
239//------------------------------------------------------------------------------
240// non-standard string functions [defined in stringFunctions.cpp]
241
242#define dStrdup(x) dStrdup_r(x, __FILE__, __LINE__)
243extern char *dStrdup_r(const char *src, const char*, dsize_t);
244
245extern char *dStrcpyl(char *dst, dsize_t dstSize, ...);
246extern char *dStrcatl(char *dst, dsize_t dstSize, ...);
247
248extern char *dStrupr(char *str);
249extern char *dStrlwr(char *str);
250
251extern char* dStrichr( char* str, char ch );
252extern const char* dStrichr( const char* str, char ch );
253
254extern S32        dStrcmp(const UTF16 *str1, const UTF16 *str2);
255extern S32        dStrnatcmp( const char* str1, const char* str2 );
256extern S32        dStrnatcasecmp( const char* str1, const char* str2 );
257
258inline bool dAtob(const char *str)
259{
260   return !dStricmp(str, "true") || dAtof(str);
261}
262
263bool dStrEqual(const char* str1, const char* str2);
264
265bool dStrStartsWith(const char* str1, const char* str2);
266
267bool dStrEndsWith(const char* str1, const char* str2);
268
269char* dStripPath(const char* filename);
270
271int dStrrev(char* str);
272int dItoa(int n, char s[]);
273
274//------------------------------------------------------------------------------
275// standard I/O functions [defined in platformString.cpp]
276
277extern void   dPrintf(const char *format, ...);
278extern S32    dVprintf(const char *format, va_list arglist);
279extern S32    dSprintf(char *buffer, U32 bufferSize, const char *format, ...);
280extern S32    dVsprintf(char *buffer, U32 bufferSize, const char *format, va_list arglist);
281extern S32    dSscanf(const char *buffer, const char *format, ...);
282
283#endif
284