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)
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)
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)
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)

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)

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)

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#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
 37// These standard functions are not defined on Win32 and other Microsoft platforms...
 38#define strcasecmp   _stricmp
 39#define strncasecmp  _strnicmp
 40
 41#if _MSC_VER < 1800
 42#define strtof       (float)strtod
 43#endif // _MSC_VER < 1800
 44
 45#endif // defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
 46
 47
 48//------------------------------------------------------------------------------
 49// standard string functions [defined in platformString.cpp]
 50
 51inline char *dStrcat(char *dst, const char *src)
 52{
 53   return strcat(dst,src);
 54}   
 55
 56inline char *dStrncat(char *dst, const char *src, dsize_t len)
 57{
 58   return strncat(dst,src,len);
 59}
 60
 61inline S32  dStrcmp(const char *str1, const char *str2)
 62{
 63   return strcmp(str1, str2);   
 64}
 65
 66inline bool dStrIsEmpty(const char *src)
 67{
 68   return src == 0 || src[0] == '\0';
 69}
 70
 71inline S32  dStrncmp(const char *str1, const char *str2, dsize_t len)
 72{
 73   return strncmp(str1, str2, len);   
 74}  
 75
 76inline S32  dStricmp(const char *str1, const char *str2)
 77{
 78   return strcasecmp( str1, str2 );
 79}
 80
 81inline S32  dStrnicmp(const char *str1, const char *str2, dsize_t len)
 82{
 83   return strncasecmp( str1, str2, len );
 84}
 85
 86inline char *dStrcpy(char *dst, const char *src)
 87{
 88   return strcpy(dst,src);
 89}   
 90
 91inline char *dStrncpy(char *dst, const char *src, dsize_t len)
 92{
 93   return strncpy(dst,src,len);
 94}   
 95
 96inline dsize_t dStrlen(const char *str)
 97{
 98   return strlen(str);
 99}   
100
101inline char *dStrchr(char *str, S32 c)
102{
103   return strchr(str,c);
104}   
105
106inline const char *dStrchr(const char *str, S32 c)
107{
108   return strchr(str,c);
109}   
110
111inline char *dStrrchr(char *str, S32 c)
112{
113   return strrchr(str,c);
114}
115
116inline const char *dStrrchr(const char *str, S32 c)
117{
118   return strrchr(str,c);
119}   
120
121inline dsize_t dStrspn(const char *str, const char *set)
122{
123   return strspn(str, set);
124}
125
126inline dsize_t dStrcspn(const char *str, const char *set)
127{
128   return strcspn(str, set);
129}   
130
131inline char *dStrstr(const char *str1, const char *str2)
132{
133   return strstr((char *)str1,str2);
134}
135
136const char* dStristr( const char* str1, const char* str2 );
137char* dStristr( char* str1, const char* str2 );
138
139
140inline char *dStrtok(char *str, const char *sep)
141{
142   return strtok(str, sep);
143}
144
145
146inline S32 dAtoi(const char *str)
147{
148   return strtol(str, NULL, 10);
149}
150
151inline U32 dAtoui(const char *str, U32 base = 10)
152{
153   return strtoul(str, NULL, base);
154}
155
156inline U16 dAtous(const char *str, U32 base = 10)
157{
158   return strtoul(str, NULL, base);
159}
160
161inline F32 dAtof(const char *str)
162{
163   return strtof(str, NULL);
164}
165
166inline F64 dAtod(const char *str)
167{
168   return strtod(str, NULL);
169}
170
171inline char dToupper(const char c)
172{
173   return toupper( c );
174}
175
176inline char dTolower(const char c)
177{
178   return tolower( c );
179}
180
181inline bool dIsalnum(const char c)
182{
183   return isalnum(c);
184}
185
186inline bool dIsalpha(const char c)
187{
188   return isalpha(c);
189}
190
191inline bool dIsspace(const char c)
192{
193   return isspace(c);
194}
195
196inline bool dIsdigit(const char c)
197{
198   return isdigit(c);
199}
200
201inline bool dIsquote(const char c)
202{
203   return ( c == '\"' );
204}
205
206//------------------------------------------------------------------------------
207// non-standard string functions [defined in stringFunctions.cpp]
208
209#define dStrdup(x) dStrdup_r(x, __FILE__, __LINE__)
210extern char *dStrdup_r(const char *src, const char*, dsize_t);
211
212extern char *dStrcpyl(char *dst, dsize_t dstSize, ...);
213extern char *dStrcatl(char *dst, dsize_t dstSize, ...);
214
215extern char *dStrupr(char *str);
216extern char *dStrlwr(char *str);
217
218extern char* dStrichr( char* str, char ch );
219extern const char* dStrichr( const char* str, char ch );
220
221extern S32        dStrcmp(const UTF16 *str1, const UTF16 *str2);
222extern S32        dStrnatcmp( const char* str1, const char* str2 );
223extern S32        dStrnatcasecmp( const char* str1, const char* str2 );
224
225inline bool dAtob(const char *str)
226{
227   return !dStricmp(str, "true") || dAtof(str);
228}
229
230bool dStrEqual(const char* str1, const char* str2);
231
232bool dStrStartsWith(const char* str1, const char* str2);
233
234bool dStrEndsWith(const char* str1, const char* str2);
235
236char* dStripPath(const char* filename);
237
238int dStrrev(char* str);
239int dItoa(int n, char s[]);
240
241//------------------------------------------------------------------------------
242// standard I/O functions [defined in platformString.cpp]
243
244extern void   dPrintf(const char *format, ...);
245extern S32    dVprintf(const char *format, va_list arglist);
246extern S32    dSprintf(char *buffer, U32 bufferSize, const char *format, ...);
247extern S32    dVsprintf(char *buffer, U32 bufferSize, const char *format, va_list arglist);
248extern S32    dSscanf(const char *buffer, const char *format, ...);
249
250#endif
251