cstring.h

Go to the documentation of this file.
00001 #ifndef CSTRING_H
00002 #define CSTRING_H
00003 
00015 #ifndef CTLSTRING_H
00016 #error This should be included from "ctl/ctlstring.h"
00017 #endif
00018 
00024 #define ctl_sconst( tchar )             ppConcat(ctl_sconst_,tchar)
00025 
00032 #define ctl_sconst_( tchar, function )  ppConcat3(ctl_sconst( tchar ),_,function)
00033 
00043 #define ctl_sconst_auto(tchar, begin, end, label ) \
00044     ctl_sconst( tchar ) label = { (begin), (begin), (end) }
00045 
00054 #define ctl_sconst_auto_string(tchar, mstr, label ) \
00055     ctl_sconst( tchar ) label = { (mstr)->begin, (mstr)->begin, (mstr)->end }
00056 
00066 #define ctl_sconst_auto_buff(tchar, buff, len, label ) \
00067     ctl_sconst( tchar ) label = { (buff), (buff), (buff)+cstrnlen(tchar)((buff),(len)) }
00068 
00077 #define ctl_sconst_auto_sz(tchar, sz, label ) \
00078     ctl_sconst( tchar ) label = { (sz), (sz), (sz)+cstrlen(tchar)((sz)) }
00079 
00088 #define ctl_sconst_auto_mmap(tchar, mmap, label ) \
00089     ctl_sconst( tchar ) label = { (const tchar*)ctl_mmap_ptr(mmap), (const tchar*)ctl_mmap_ptr(mmap), (const tchar*)ctl_mmap_ptr(mmap)+ctl_mmap_size(mmap) }
00090 
00099 #define ctl_sconst_init(tchar, self, buff, len )\
00100 {\
00101     (self)->parse = (self)->begin = (buff);\
00102     (self)->end = (self)->begin + cstrnlen(tchar)((buff),(len));\
00103 }
00104 
00112 #define ctl_sconst_init_sz(tchar, self, sz )\
00113 {\
00114     (self)->parse = (self)->begin = (sz);\
00115     (self)->end = (self)->begin + cstrlen(tchar)(sz);\
00116 }
00117 
00125 #define ctl_sconst_init_mmap(tchar, self, mmap )\
00126 {\
00127     (self)->parse = (self)->begin = (const tchar*)ctl_mmap_ptr(mmap);\
00128     (self)->end = (self)->begin + ctl_mmap_size(mmap);\
00129 }
00130 
00137 #define ctl_sconst_printf_fmt(tchar)    szconst(tchar,"%.*s")
00138 
00145 #define ctl_sconst_printf_arg(self)     ((self)->end - (self)->begin), (self)->begin
00146 
00154 #define ctl_sconst_copy(tchar, self, from )\
00155 {\
00156     (self)->begin = (from)->begin;\
00157     (self)->parse = (from)->parse;\
00158     (self)->end = (from)->end;\
00159 }
00160 
00169 #define ctl_sconst_init_pointers(tchar, self, pBegin, pEnd )\
00170 {\
00171     (self)->parse = (self)->begin = (pBegin);\
00172     (self)->end = (pEnd);\
00173     assert( (self)->end >= (self)->begin );\
00174 }
00175 
00183 #define ctl_sconst_from_ctlfixed(tchar, self, fixed ) \
00184 {\
00185     (self)->parse = (self)->begin = (fixed)->begin;\
00186     (self)->end = (fixed)->end;\
00187 }
00188 
00197 #define ctl_sconst_from_ctlstring( tchar, self, variable )\
00198 {\
00199     (self)->parse = (self)->begin = (variable)->begin;\
00200     (self)->end = (self)->begin + (variable)->(len);\
00201 }
00202 
00210 #define ctl_sconst_remain(tchar, self )     ( (self)->end - (self)->parse )
00211 
00219 #define ctl_sconst_consumed(tchar, self )   ( (self)->parse - (self)->begin )
00220 
00228 #define ctl_sconst_size(tchar, self )       ((size_t)( (self)->end - (self)->begin ))
00229 
00237 #define ctl_sconst_parse(tchar, self )      ( (self)->parse )
00238 
00246 #define ctl_sconst_reset(tchar, self )      ( (self)->parse = (self)->begin )
00247 
00255 #define ctl_sconst_begin(tchar, self )      ( (self)->begin )
00256 
00264 #define ctl_sconst_end(tchar, self )        ( (self)->end )
00265 
00273 #define ctl_sconst_next(tchar, self )       ( (self)->parse < (self)->end ? (++(self)->parse) : (self)->end )
00274 
00282 #define ctl_sconst_prev(tchar, self )       ( (self)->parse > (self)->begin ? (--(self)->parse) : (self)->begin )
00283 
00291 #define ctl_sconst_isalnum(tchar, self )    ( cisalnum(tchar)(*(self)->parse) )
00292 
00300 #define ctl_sconst_isalpha(tchar, self )    ( cisalpha(tchar)(*(self)->parse) )
00301 
00309 #define ctl_sconst_iscntrl(tchar, self )    ( ciscntrl(tchar)(*(self)->parse) )
00310 
00318 #define ctl_sconst_isdigit(tchar, self )    ( cisdigit(tchar)(*(self)->parse) )
00319 
00327 #define ctl_sconst_isgraph(tchar, self )    ( cisgraph(tchar)(*(self)->parse) )
00328 
00336 #define ctl_sconst_islower(tchar, self )    ( cislower(tchar)(*(self)->parse) )
00337 
00345 #define ctl_sconst_ispunct(tchar, self )    ( cispunct(tchar)(*(self)->parse) )
00346 
00354 #define ctl_sconst_isspace(tchar, self )    ( cisspace(tchar)(*(self)->parse) )
00355 
00363 #define ctl_sconst_isupper(tchar, self )    ( cisupper(tchar)(*(self)->parse) )
00364 
00372 #define ctl_sconst_isprint(tchar, self )    ( cisprint(tchar)(*(self)->parse) )
00373 
00381 #define ctl_sconst_isxdigit(tchar, self )   ( cisxdigit(tchar)(*(self)->parse) )
00382 
00391 #define ctl_sconst_left(tchar, self, cstr_left, count ) \
00392 {\
00393     (cstr_left)->begin = (cstr_left)->parse = (self)->(begin);\
00394     (cstr_left)->end = (cstr_left)->begin + (count);\
00395     if( (cstr_left)->end > (self)->end )\
00396         (cstr_left)->end = (self)->end;\
00397 }
00398 
00407 #define ctl_sconst_right(tchar, self, cstr_right, count )\
00408 {\
00409     (cstr_right)->begin = (cstr_right)->parse = (self)->(end)-(count);\
00410     (cstr_right)->end = (self)->end;\
00411     if( (cstr_right)->begin < (self)->begin )\
00412         (cstr_right)->begin = (self)->begin;\
00413 }
00414 
00424 #define ctl_sconst_mid(tchar, self, cstr_mid, offset, count )\
00425 {\
00426     (cstr_mid)->begin = (cstr_mid)->parse = (self)->begin + (offset);\
00427     (cstr_mid)->end = (cstr_mid)->begin + (count);\
00428     if( (cstr_mid)->begin > (self)->end )\
00429     {\
00430         (cstr_mid)->begin = (self)->end;\
00431         (cstr_mid)->end = (self)->end;\
00432     }\
00433     if( (cstr_mid)->end > (self)->end )\
00434         (cstr_mid)->end = (self)->end;\
00435 }
00436 
00445 #define ctl_sconst_strchr(tchar, self, ch )                                 ctl_sconst_(tchar,strchr)( self, ch )
00446 
00455 #define ctl_sconst_strichr(tchar, self, ch )                                ctl_sconst_(tchar,strichr)( self, ch )
00456 
00465 #define ctl_sconst_strstr(tchar, self, sz )                                 ctl_sconst_(tchar,strstr)( self, sz )
00466 
00475 #define ctl_sconst_stristr(tchar, self, sz )                                ctl_sconst_(tchar,stristr)( self, sz )
00476 
00488 #define ctl_sconst_dmatch(tchar, self, substring, chOpen, chClose )         ctl_sconst_(tchar,dmatch)( self, substring, chOpen, chClose )
00489 
00500 #define ctl_sconst_dmatchstr(tchar, self, substring, szOpen, szClose )      ctl_sconst_(tchar,dmatchstr)( self, substring, szOpen, szClose )
00501 
00510 #define ctl_sconst_strpbrk(tchar, self, szSet )                             ctl_sconst_(tchar,strpbrk)( self, szSet )
00511 
00519 #define ctl_sconst_skipspace(tchar, self )                                  ctl_sconst_(tchar,skipspace)( self )
00520 
00528 #define ctl_sconst_nextspace(tchar, self )                                  ctl_sconst_(tchar,nextspace)( self )
00529 
00538 #define ctl_sconst_findclass( tchar, self, classname )                      ctl_sconst_(tchar,ppConcat(find_,classname))( self )
00539 
00548 #define ctl_sconst_findnotclass( tchar, self, classname )                   ctl_sconst_(tchar,ppConcat(find_not_,classname))( self )
00549 
00559 #define ctl_sconst_scanclass( tchar, self, found, classname )               ctl_sconst_(tchar,ppConcat(scan_,classname))( self, found )
00560 
00570 #define ctl_sconst_scannotclass( tchar, self, found, classname )            ctl_sconst_(tchar,ppConcat(scan_not_,classname))( self, found )
00571 
00580 #define ctl_sconst_strcmp(tchar, self, sz )                                 ctl_sconst_(tchar,strcmp)( self, sz )
00581 
00590 #define ctl_sconst_stricmp(tchar, self, sz )                                ctl_sconst_(tchar,stricmp)( self, sz )
00591 
00601 #define ctl_sconst_strncmp(tchar, self, sz, count )                         ctl_sconst_(tchar,strncmp)( self, sz, count )
00602 
00612 #define ctl_sconst_strnicmp(tchar, self, sz, count )                        ctl_sconst_(tchar,strnicmp)( self, sz, count )
00613 
00622 #define ctl_sconst_compare(tchar, p1, p2 )                              ctl_sconst_(tchar,compare)( (p1),(p2) )
00623 
00632 #define ctl_sconst_rcompare(tchar, p1, p2 )                             ctl_sconst_(tchar,compare)( (p2),(p1) )
00633 
00642 #define ctl_sconst_icompare(tchar, self, other )                            ctl_sconst_(tchar,icompare)( (self), (other) )
00643 
00652 #define ctl_sconst_getbool(tchar, self, pValue )                            ctl_sconst_(tchar,getbool)( self, pValue )
00653 
00662 #define ctl_sconst_getint8(tchar, self, pValue )                            ctl_sconst_(tchar,getint8)( self, pValue )
00663 
00672 #define ctl_sconst_getuint8(tchar, self, pValue )                           ctl_sconst_(tchar,getuint8)( self, pValue )
00673 
00682 #define ctl_sconst_getint16(tchar, self, pValue )                           ctl_sconst_(tchar,getint16)( self, pValue )
00683 
00692 #define ctl_sconst_getuint16(tchar, self, pValue )                          ctl_sconst_(tchar,getuint16)( self, pValue )
00693 
00702 #define ctl_sconst_getint32(tchar, self, pValue )                           ctl_sconst_(tchar,getint32)( self, pValue )
00703 
00712 #define ctl_sconst_getuint32(tchar, self, pValue )                          ctl_sconst_(tchar,getuint32)( self, pValue )
00713 
00722 #define ctl_sconst_getint64(tchar, self, pValue )                           ctl_sconst_(tchar,getint64)( self, pValue )
00723 
00732 #define ctl_sconst_getuint64(tchar, self, pValue )                          ctl_sconst_(tchar,getuint64)( self, pValue )
00733 
00742 #define ctl_sconst_getfloat32(tchar, self, pValue )                         ctl_sconst_(tchar,getfloat32)( self, pValue )
00743 
00753 #define ctl_sconst_getfloat64(tchar, self, pValue )                         ctl_sconst_(tchar,getfloat64)( self, pValue )
00754 
00763 #define ctl_sconst_getxbool(tchar, self, pValue )                           ctl_sconst_(tchar,getbool)( self, pValue )
00764 
00773 #define ctl_sconst_getxint8(tchar, self, pValue )                           ctl_sconst_(tchar, getxint8 )( self, pValue )
00774 
00783 #define ctl_sconst_getxuint8(tchar, self, pValue )                          ctl_sconst_(tchar, getxuint8 )( self, pValue )
00784 
00793 #define ctl_sconst_getxint16(tchar, self, pValue )                          ctl_sconst_(tchar, getxint16 )( self, pValue )
00794 
00803 #define ctl_sconst_getxuint16(tchar, self, pValue )                         ctl_sconst_(tchar, getxuint16 )( self, pValue )
00804 
00813 #define ctl_sconst_getxint32(tchar, self, pValue )                          ctl_sconst_(tchar, getxuint32 )( self, (uint32*)(pValue), 8 )
00814 
00823 #define ctl_sconst_getxuint32(tchar, self, pValue )                         ctl_sconst_(tchar, getxuint32 )( self, pValue, 8 )
00824 
00833 #define ctl_sconst_getxint64(tchar, self, pValue )                          ctl_sconst_(tchar, getxuint64 )( self, (uint64*)(pValue), 16 )
00834 
00843 #define ctl_sconst_getxuint64(tchar, self, pValue )                         ctl_sconst_(tchar, getxuint64 )( self, pValue, 16 )
00844 
00855 #define ctl_sconst_getxn(tchar, self, pValue, numDigits )                   ctl_sconst_(tchar, getx64 )( self, pValue, numDigits )
00856 
00867 #define ctl_sconst_getxnn(tchar, self, pValue, numDigits )                  ctl_sconst_(tchar, getx64 )( self, pValue, numDigits )
00868 
00879 #define ctl_sconst_getenum(tchar, self, pValue, szz )                       ctl_sconst_(tchar,getenum)( self, pValue, szz )
00880 
00891 #define ctl_sconst_getienum(tchar, self, pValue, szz )                      ctl_sconst_(tchar,getienum)( self, pValue, szz )
00892 
00893 
00915 #define ctldecl_ctl_sconst(tchar) \
00916 \
00920 typedef struct ctl_sconst( tchar ) \
00921 {\
00922     const tchar*    begin;  /* First valid character within this string/substring */\
00923     const tchar*    parse;  /* Current point at which string parsing is proceeding */\
00924     const tchar*    end;    /* One character after the last valid character within this string/substring */\
00925 } ctl_sconst( tchar );\
00926 bool ctl_sconst_(tchar, strchr )( ctl_sconst( tchar )* self, tchar ch );\
00927 bool ctl_sconst_(tchar, strichr )( ctl_sconst( tchar )* self, tchar ch );\
00928 bool ctl_sconst_(tchar, strstr )( ctl_sconst( tchar )* self, const tchar* sz );\
00929 bool ctl_sconst_(tchar, stristr )( ctl_sconst( tchar )* self, const tchar* sz );\
00930 bool ctl_sconst_(tchar, dmatch )( ctl_sconst( tchar )* self, ctl_sconst( tchar )* substring, tchar chOpen, tchar chClose );\
00931 bool ctl_sconst_(tchar, dmatchstr )( ctl_sconst( tchar )* self, ctl_sconst( tchar )* substring, const tchar* szOpen, const tchar* szClose );\
00932 bool ctl_sconst_(tchar, strpbrk )( ctl_sconst( tchar )* self, const tchar* szSet );\
00933 bool ctl_sconst_(tchar, skipspace )( ctl_sconst( tchar )* self );\
00934 bool ctl_sconst_(tchar, nextspace )( ctl_sconst( tchar )* self );\
00935 int  ctl_sconst_(tchar, strcmp )( const ctl_sconst( tchar )* self, const tchar* sz );\
00936 int  ctl_sconst_(tchar, stricmp )( const ctl_sconst( tchar )* self, const tchar* sz );\
00937 int  ctl_sconst_(tchar, strncmp )( const ctl_sconst( tchar )* self, const tchar* sz, size_t count );\
00938 int  ctl_sconst_(tchar, strnicmp )( const ctl_sconst( tchar )* self, const tchar* sz, size_t count );\
00939 int  ctl_sconst_(tchar, compare )( const ctl_sconst( tchar )* self, const ctl_sconst( tchar )* other );\
00940 int  ctl_sconst_(tchar, icompare )( const ctl_sconst( tchar )* self, const ctl_sconst( tchar )* other );\
00941 bool ctl_sconst_(tchar, getbool )( ctl_sconst( tchar )* self, bool* pValue );\
00942 bool ctl_sconst_(tchar, getint8 )( ctl_sconst( tchar )* self, int8* pValue );\
00943 bool ctl_sconst_(tchar, getuint8 )( ctl_sconst( tchar )* self, uint8* pValue );\
00944 bool ctl_sconst_(tchar, getint16 )( ctl_sconst( tchar )* self, int16* pValue );\
00945 bool ctl_sconst_(tchar, getuint16 )( ctl_sconst( tchar )* self, uint16* pValue );\
00946 bool ctl_sconst_(tchar, getint32 )( ctl_sconst( tchar )* self, int32* pValue );\
00947 bool ctl_sconst_(tchar, getuint32 )( ctl_sconst( tchar )* self, uint32* pValue );\
00948 bool ctl_sconst_(tchar, getint64 )( ctl_sconst( tchar )* self, int64* pValue );\
00949 bool ctl_sconst_(tchar, getuint64 )( ctl_sconst( tchar )* self, uint64* pValue );\
00950 bool ctl_sconst_(tchar, getfloat32 )( ctl_sconst( tchar )* self, float32* pValue );\
00951 bool ctl_sconst_(tchar, getfloat64 )( ctl_sconst( tchar )* self, float64* pValue );\
00952 bool ctl_sconst_(tchar, getxint8 )( ctl_sconst( tchar )* self, int8* pValue );\
00953 bool ctl_sconst_(tchar, getxuint8 )( ctl_sconst( tchar )* self, uint8* pValue );\
00954 bool ctl_sconst_(tchar, getxint16 )( ctl_sconst( tchar )* self, int16* pValue );\
00955 bool ctl_sconst_(tchar, getxuint16 )( ctl_sconst( tchar )* self, uint16* pValue );\
00956 bool ctl_sconst_(tchar, getxuint32 )( ctl_sconst( tchar )* self, uint32* pValue, int numDigits );\
00957 bool ctl_sconst_(tchar, getxuint64 )( ctl_sconst( tchar )* self, uint64* pValue, int numDigits );\
00958 bool ctl_sconst_(tchar, getenum )( ctl_sconst( tchar )* self, int* pValue, const tchar* const* szzList );\
00959 bool ctl_sconst_(tchar, getienum )( ctl_sconst( tchar )* self, int* pValue, const tchar* const* szzList );\
00960 DEF_Supported_Class_Scans(tchar,decl_sconst_findclass)\
00961 DEF_Supported_Class_Scans(tchar,decl_sconst_findnotclass)\
00962 DEF_Supported_Class_Scans(tchar,decl_sconst_scanclass)\
00963 DEF_Supported_Class_Scans(tchar,decl_sconst_scannotclass)\
00964 
00965 
00972 #define DEF_Supported_Class_Scans( tchar, def )\
00973     def( tchar, isalnum )\
00974     def( tchar, isalpha )\
00975     def( tchar, iscntrl )\
00976     def( tchar, isdigit )\
00977     def( tchar, isgraph )\
00978     def( tchar, islower )\
00979     def( tchar, ispunct )\
00980     def( tchar, isspace )\
00981     def( tchar, isupper )\
00982     def( tchar, isprint )\
00983     def( tchar, isxdigit )
00984 
00986 #define decl_sconst_findclass( tchar, classname)    bool ctl_sconst_(tchar, ppConcat(find_,classname) )( ctl_sconst( tchar )* self );
00987 #define decl_sconst_findnotclass( tchar, classname) bool ctl_sconst_(tchar, ppConcat(find_not_,classname) )( ctl_sconst( tchar )* self );
00988 #define decl_sconst_scanclass( tchar, classname)    bool ctl_sconst_(tchar, ppConcat(scan_,classname) )( ctl_sconst( tchar )* self, ctl_sconst( tchar )* result );
00989 #define decl_sconst_scannotclass( tchar, classname) bool ctl_sconst_(tchar, ppConcat(scan_not_,classname) )( ctl_sconst( tchar )* self, ctl_sconst( tchar )* result );
00990 
00991 /* Manufacture template declarations for char, wchar_t */
00992 ctldecl_ctl_sconst(char)
00993 ctldecl_ctl_sconst(wchar_t)
00994 
01002 #define ctl_sconst_foreach(tchar,self,iterator) \
01003     const tchar* iterator = (self)->begin;\
01004     const tchar* ppConcat(end_,iterator) = (self)->end;\
01005     for( ; iterator < ppConcat(end_,iterator); ++iterator )
01006 
01014 #define ctl_sconst_foreach_reverse(tchar,self,iterator) \
01015     const tchar* iterator = (self)->end;\
01016     const tchar* ppConcat(end_,iterator) = (self)->begin;\
01017     while( iterator-- < ppConcat(end_,iterator) )
01018 
01019 #endif /* CSTRING_H */
01020 

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