ctlstring.h

Go to the documentation of this file.
00001 #ifndef CTLSTRING_H
00002 #define CTLSTRING_H
00003 
00017 #include <string.h>
00018 #include <ctype.h>
00019 #include <wctype.h>
00020 #include <wchar.h>
00021 #include <stdarg.h>
00022 
00029 #define chconst(tchar,ch)   ppConcat(chconst_,tchar)(ch)
00030 #define chconst_char(ch)    ((char)(ch))
00031 #define chconst_wchar_t(ch) ((wchar_t)(ch))
00032 
00039 #define szconst(tchar,sz)   ppConcat(szconst_,tchar)(sz)
00040 #define szconst_char(sz)    sz
00041 #define szconst_wchar_t(sz) ppConcat(L,sz)
00042 
00050 #define szconvert(tchardst,tcharsrc)(ch)    ppConcat3(szconvert_,tchardst,tcharsrc)
00051 #define szconvert_charchar(ch)              (ch)
00052 #define szconvert_charwchar_t(ch)           ((char)(ch))
00053 #define szconvert_wchar_tchar(ch)           ((wchar_t)(ch))
00054 #define szconvert_wchar_twchar_t(ch)        (ch)
00055 
00062 #define szstrfmt(tchar)             ppConcat(szstrfmt_,tchar)
00063 #define szstrfmt_char               "s"
00064 #define szstrfmt_wchar_t            L"ls"
00065 
00073 #define ctl_chsize(tchar,length)        (ppCtypeSelect(tchar,(size_t)(length),(length)*sizeof(tchar)))
00074 
00082 #define ctl_chlength(tchar,size)        (ppCtypeSelect(tchar,(size_t)(size),(size)/sizeof(tchar)))
00083 
00084 /*
00085  * Force some trivial standardization on naming - these are not necessarily 
00086  * used by the provided template classes, as many variations on the theme 
00087  * do not have boundary-safe equivalents, as used by these classes.  They're
00088  * just here to make the application code a little less messily portable.
00089  */
00090 #ifdef WIN32
00091 #define swprintf        _snwprintf      /*  VC '05 & '08 have issues with swprintf; the %ls field crashes it.*/
00092 #define vswprintf       _vsnwprintf     /* It DOES work right when snwprintf or vsnwprintf are called.  Why?  Don't know, don't care. */
00093 #endif
00094 #ifdef _MSC_VER /* Microsoft decided to put these underscores onto standard functions to let you know that Microsoft doesn't adhere to standards. */
00095 #define snprintf        _snprintf
00096 #if _MSC_VER < 1500 /* VC '08 this causes some issues */
00097 #define vsnprintf       _vsnprintf
00098 #endif
00099 #define strtof          (float)strtod
00100 #define wcstof          (float)wcstod
00101 #define itoa            _itoa
00102 #define itow            _itow
00103 #define strdup          _strdup
00104 #define wcsdup          _wcsdup
00105 #define stricmp         _stricmp
00106 #define wcsicmp         _wcsicmp
00107 #define strnicmp        _strnicmp
00108 #define wcsnicmp        _wcsnicmp
00109 #define strtoll         _strtoi64
00110 #define wcstoll         _wcstoi64
00111 #define strtoull        _strtoui64
00112 #define wcstoull        _wcstoui64
00113 #define strupr          _strupr
00114 #define wcsupr          _wcsupr
00115 #define strlwr          _strlwr
00116 #define wcslwr          _wcslwr
00117 #define putws           _putws
00118 #endif /* _MSC_VER */
00119 #if defined(__GNUC__)   /* A few other quirks */
00120 #if defined(WIN32)
00121 #else
00122 #define strtof          (float)strtod
00123 #define wcstof          (float)wcstod
00124 #define __putws(s)      fputws(stdout,s)
00125 #define putws           __putws
00126 #define stricmp         strcasecmp
00127 #define wcsicmp         wcscasecmp
00128 #define strnicmp        strncasecmp
00129 #define wcsnicmp        wcsncasecmp
00130 #endif
00131 #ifdef __CYGWIN__
00132 int wcsncasecmp( const wchar_t* sz1, const wchar_t* sz2, size_t max );
00133 double wcstod( const wchar_t* sz, wchar_t** ppsz );
00134 long wcstol( const wchar_t* sz, wchar_t** psz, int radix );
00135 #endif
00136 #endif /* __GNUC__ */
00137 
00138 
00146 #define ppCtypeSelect(tchar,xchar,xwchar_t)     ppConcat(_ppCtypeSelect_,tchar)(xchar,xwchar_t)
00147 #define _ppCtypeSelect_char(xchar,xwchar_t)     xchar
00148 #define _ppCtypeSelect_wchar_t(xchar,xwchar_t)  xwchar_t
00149 
00156 #define chssize(tchar,length)       (ppCtypeSelect(tchar,(size_t)(length),(length)*2))
00157 
00164 #define chslength(tchar,size)       (ppCtypeSelect(tchar,(size_t)(size),(size)/2))
00165 
00166 /* 
00167  * These are template helpers to select the appropriate function name from
00168  * the input character type.  Mostly, it's str<->wcs, is<->isw, to<->tow
00169  */
00170 #define cisalnum(tchar)             ppCtypeSelect(tchar,isalnum,iswalnum)
00171 #define cisalpha(tchar)             ppCtypeSelect(tchar,isalpha,iswalpha)
00172 #define ciscntrl(tchar)             ppCtypeSelect(tchar,iscntrl,iswcntrl)
00173 #define cisdigit(tchar)             ppCtypeSelect(tchar,isdigit,iswdigit)
00174 #define cisgraph(tchar)             ppCtypeSelect(tchar,isgraph,iswgraph)
00175 #define cislower(tchar)             ppCtypeSelect(tchar,islower,iswlower)
00176 #define cispunct(tchar)             ppCtypeSelect(tchar,ispunct,iswpunct)
00177 #define cisspace(tchar)             ppCtypeSelect(tchar,isspace,iswspace)
00178 #define cisupper(tchar)             ppCtypeSelect(tchar,isupper,iswupper)
00179 #define cisprint(tchar)             ppCtypeSelect(tchar,isprint,iswprint)
00180 #define cisxdigit(tchar)            ppCtypeSelect(tchar,isxdigit,iswxdigit)
00181 #define ctolower(tchar)             (tchar)ppCtypeSelect(tchar,tolower,towlower)
00182 #define ctoupper(tchar)             (tchar)ppCtypeSelect(tchar,toupper,towupper)
00183 
00184 /* Stdio style */
00185 #define cprintf(tchar)              ppCtypeSelect(tchar,printf,wprintf)
00186 #define csprintf(tchar)             ppCtypeSelect(tchar,sprintf,swprintf)
00187 #define cvprintf(tchar)             ppCtypeSelect(tchar,vprintf,vwprintf)
00188 #define csnprintf(tchar)            ppCtypeSelect(tchar,snprintf,swprintf)
00189 #define cvsnprintf(tchar)           ppCtypeSelect(tchar,vsnprintf,vswprintf)
00190 #define cfprintf(tchar)             ppCtypeSelect(tchar,fprintf,fwprintf)
00191 #define cvfprintf(tchar)            ppCtypeSelect(tchar,vfprintf,vfwprintf)
00192 #define cscanf(tchar)               ppCtypeSelect(tchar,scanf,wscanf)
00193 #define csscanf(tchar)              ppCtypeSelect(tchar,sscanf,swscanf)
00194 #define cfscanf(tchar)              ppCtypeSelect(tchar,fscanf,fwscanf)
00195 #define cscanf(tchar)               ppCtypeSelect(tchar,scanf,wscanf)
00196 #define csscanf(tchar)              ppCtypeSelect(tchar,sscanf,swscanf)
00197 #define cputs(tchar)                ppCtypeSelect(tchar,puts,putws)
00198 #define cputchar(tchar)             ppCtypeSelect(tchar,putchar,putwchar)
00199 #define cfputs(tchar)               ppCtypeSelect(tchar,fputs,fputws)
00200 #define cfputc(tchar)               ppCtypeSelect(tchar,fputc,fputwc)
00201 #define cfgets(tchar)               ppCtypeSelect(tchar,fgets,fgetws)
00202 #define cfgetc(tchar)               ppCtypeSelect(tchar,fgetc,fgetwc)
00203 #define cfungetc(tchar)             ppCtypeSelect(tchar,ungetc,ungetwc)
00204 
00205 /* String style */
00206 #define cstrcat(tchar)              ppCtypeSelect(tchar,strcat,wcscat)
00207 #define cstrpbrk(tchar)             ppCtypeSelect(tchar,strpbrk,wcspbrk)
00208 #define cstrchr(tchar)              ppCtypeSelect(tchar,strchr,wcschr)
00209 #define cstrrchr(tchar)             ppCtypeSelect(tchar,strrchr,wcsrchr)
00210 #define cstrcmp(tchar)              ppCtypeSelect(tchar,strcmp,wcscmp)
00211 #define cstrcpy(tchar)              ppCtypeSelect(tchar,strcpy,wcscpy)
00212 #define cstrspn(tchar)              ppCtypeSelect(tchar,strspn,wcsspn)
00213 #define cstrstr(tchar)              ppCtypeSelect(tchar,strstr,wcsstr)
00214 #define cstrtok(tchar)              ppCtypeSelect(tchar,strtok,wcstok)
00215 #define cstrdup(tchar)              ppCtypeSelect(tchar,strdup,wcsdup)
00216 #define cstricmp(tchar)             ppCtypeSelect(tchar,stricmp,wcsicmp)
00217 #define cstrlen(tchar)              ppCtypeSelect(tchar,strlen,wcslen)
00218 #define cstrupr(tchar)              ppCtypeSelect(tchar,strupr,wcsupr)
00219 #define cstrlwr(tchar)              ppCtypeSelect(tchar,strlwr,wcslwr)
00220 #define cstrnlen(tchar)             ppCtypeSelect(tchar,strnlen,wcsnlen)
00221 #define cstrncat(tchar)             ppCtypeSelect(tchar,strncat,wcsncat)
00222 #define cstrncmp(tchar)             ppCtypeSelect(tchar,strncmp,wcsncmp)
00223 #define cstrnicmp(tchar)            ppCtypeSelect(tchar,strnicmp,wcsnicmp)
00224 #define cstrncpy(tchar)             ppCtypeSelect(tchar,strncpy,wcsncpy)
00225 
00226 /* Some numeric parsers */
00227 #define citoa(tchar)                ppCtypeSelect(tchar,itoa,itow)
00228 #define cstrtol(tchar)              ppCtypeSelect(tchar,strtol,wcstol)
00229 #define cstrtoul(tchar)             ppCtypeSelect(tchar,strtoul,wcstoul)
00230 #define cstrtoll(tchar)             ppCtypeSelect(tchar,strtoll,wcstoll)
00231 #define cstrtoull(tchar)            ppCtypeSelect(tchar,strtoull,wcstoull)
00232 #define cstrtoq(tchar)              ppCtypeSelect(tchar,strtoq,wcstoq)
00233 #define cstrtouq(tchar)             ppCtypeSelect(tchar,strtouq,wcstouq)
00234 #define cstrtod(tchar)              ppCtypeSelect(tchar,strtod,wcstod)
00235 #define cstrtof(tchar)              ppCtypeSelect(tchar,strtof,wcstof)
00236 
00237 #define cstrwild(tchar)             ppCtypeSelect(tchar,strwild,wcswild)
00238 #define cstrnupper(tchar)           ppCtypeSelect(tchar,strnupper,wcsnupper)
00239 #define cstrnlower(tchar)           ppCtypeSelect(tchar,strnlower,wcsnlower)
00240 #define cstrnlabel(tchar)           ppCtypeSelect(tchar,strnlabel,wcsnlabel)
00241 
00242 #ifdef __GNUC__
00243 size_t strnlen( const char* sz, size_t max );
00244 size_t wcsnlen( const wchar_t* sz, size_t max );
00245 #endif /* __GNUC__ */
00246 char* strnlabel( char* buff, const char* src, size_t buffSize );
00247 char* strnupper( char* buff, const char* src, size_t buffSize );
00248 char* strnlower( char* buff, const char* src, size_t buffSize );
00249 wchar_t* wcsnlabel( wchar_t* buff, const wchar_t* src, size_t buffSize );
00250 wchar_t* wcsnupper( wchar_t* buff, const wchar_t* src, size_t buffSize );
00251 wchar_t* wcsnlower( wchar_t* buff, const wchar_t* src, size_t buffSize );
00252 
00253 
00254 
00263 #define cmemcpy(tchar, sDst, sSrc, count )  memcpy( (sDst),(sSrc),ctl_chsize(tchar,count) )
00264 
00273 #define cmemmove(tchar, sDst, sSrc, count ) memmove( (sDst),(sSrc),ctl_chsize(tchar,count) )
00274 
00275 
00276 /* Include our string types */
00277 #include "ctl/cstring.h"    /* Const strings */
00278 #include "ctl/mstring.h"    /* Mutable string base */
00279 #include    "ctl/fstring.h" /* Fixed buffer string */
00280 #include    "ctl/gstring.h" /* Growable string */
00281 
00282 #endif /* CTLSTRING_H */

Generated on Fri Jan 2 15:28:34 2009 for Squat by  doxygen 1.5.6