00001 #ifndef GSTRING_H
00002 #define GSTRING_H
00003
00014 #ifndef CTLSTRING_H
00015 #error This should be included from "ctl/ctlstring.h"
00016 #endif
00017
00024 #define ctl_gstring(tchar) ctl_mstring(tchar,grow)
00025
00027 #define ctl_gstring_(tchar) ctl_mstring_(tchar,grow)
00028
00035 #define ctl_gstring_destroy(tchar, self )\
00036 {\
00037 if( (self)->begin != ctl_mstring_(tchar,grow,0) ) \
00038 ctl_free((self)->begin); \
00039 (self)->begin = (self)->endBuff = (self)->end = (tchar*)ctl_mstring_(tchar,grow,0);\
00040 }
00041
00049 #define ctl_gstring_auto(tchar, label )\
00050 ctl_mstring(tchar,grow) label = {(tchar*)ctl_mstring_(tchar,grow,0),(tchar*)ctl_mstring_(tchar,grow,0),(tchar*)ctl_mstring_(tchar,grow,0)}
00051
00058 #define ctl_gstring_init(tchar, self )\
00059 (self)->begin = (self)->end = (self)->endBuff = (tchar*)ctl_mstring_(tchar,grow,0)\
00060
00061
00068 #define ctl_gstring_init_sz(tchar, self, sz )\
00069 {\
00070 (self)->begin = (self)->end = (self)->endBuff = (tchar*)ctl_mstring_(tchar,grow,0);\
00071 ctl_gstring_strcpy(tchar, (self), (sz) );\
00072 }
00073
00081 #define ctl_gstring_init_cstring(tchar, self, cstr )\
00082 {\
00083 (self)->begin = (self)->end = (self)->endBuff = (tchar*)ctl_mstring_(tchar,grow,0);\
00084 ctl_gstring_strncpy(tchar, (self), (cstr)->begin, (cstr)->end-(cstr)->begin );\
00085 }
00086
00094 #define ctl_gstring_swap(tchar, p1, p2 )\
00095 {\
00096 ctl_gstring(tchar) tmp = *(p1);\
00097 *(p1) = *(p2);\
00098 *(p2) = tmp;\
00099 }
00100
00108 #define ctl_gstring_move(tchar, p1, p2 )\
00109 {\
00110 (p1)->begin = (p2)->begin;\
00111 (p1)->end = (p2)->end;\
00112 (p1)->endBuff = (p2)->endBuff;\
00113 (p2)->begin = (p2)->end = (p2)->endBuff = NULL;\
00114 }
00115
00123 #define ctl_gstring_remain(tchar, self ) ( (self)->endBuff - (self)->end )
00124
00132 #define ctl_gstring_size(tchar, self ) ((size_t)( (self)->end - (self)->begin ))
00133
00141 #define ctl_gstring_reset(tchar, self ) { if( (self)->begin != ctl_mstring_(tchar,grow,0) ) { (self)->end = (self)->begin; *(self)->begin = 0; } }
00142
00150 #define ctl_gstring_begin(tchar, self ) ( (self)->begin )
00151
00159 #define ctl_gstring_end(tchar, self ) ( (self)->end )
00160
00168 #define ctl_gstring_resize(tchar, self, count ) { ctl_mstring_(tchar,grow, grow )( (self), (count) - ((self)->end-(self)->begin) ); *((self)->end = (self)->begin+(count)) = 0; }
00169
00178 #define ctl_gstring_fill(tchar, self, fillVal, count ) ctl_mstring_(tchar,grow, fill )((self), (fillVal), (count) )
00179
00187 #define ctl_gstring_add(tchar, self, ch ) ctl_mstring_(tchar,grow, fill )((self), (ch), 1 )
00188
00197 #define ctl_gstring_filltab(tchar, self, fillVal, tabPos ) ctl_mstring_(tchar,grow, filltab )((self), (fillVal), (tabPos) )
00198
00206 #define ctl_gstring_putbool(tchar, self, value ) ctl_mstring_(tchar,grow, strncat )((self),(value) ? szconst(tchar,"true") : szconst(tchar,"false"), ~0u )
00207
00215 #define ctl_gstring_putboolyesno(tchar, self, value ) ctl_mstring_(tchar,grow, strncat )((self),(value) ? szconst(tchar,"yes") : szconst(tchar,"no"), ~0u )
00216
00224 #define ctl_gstring_putboolonoff(tchar, self, value ) ctl_mstring_(tchar,grow, strncat )((self),(value) ? szconst(tchar,"on") : szconst(tchar,"off"), ~0u )
00225
00233 #define ctl_gstring_putbool10(tchar, self, value ) ctl_mstring_(tchar,grow, strncat )((self),(value) ? szconst(tchar,"1") : szconst(tchar,"0"), ~0u )
00234
00242 #define ctl_gstring_putint8(tchar, self, value ) ctl_mstring_(tchar,grow, putint32 )((self),(int32)(int8)(value) )
00243
00251 #define ctl_gstring_putuint8(tchar, self, value ) ctl_mstring_(tchar,grow, putuint32 )((self),(uint32)(uint8)(value) )
00252
00260 #define ctl_gstring_putint16(tchar, self, value ) ctl_mstring_(tchar,grow, putint32 )((self),(int32)(int16)(value) )
00261
00269 #define ctl_gstring_putuint16(tchar, self, value ) ctl_mstring_(tchar,grow, putuint32 )((self),(uint32)(uint16)(value) )
00270
00278 #define ctl_gstring_putint32(tchar, self, value ) ctl_mstring_(tchar,grow, putint32 )((self),(value) )
00279
00287 #define ctl_gstring_putuint32(tchar, self, value ) ctl_mstring_(tchar,grow, putuint32 )((self),(value) )
00288
00296 #define ctl_gstring_putint64(tchar, self, value ) ctl_mstring_(tchar,grow, putint64 )((self),(value) )
00297
00305 #define ctl_gstring_putuint64(tchar, self, value ) ctl_mstring_(tchar,grow, putuint64 )((self),(value) )
00306
00314 #define ctl_gstring_putfloat32(tchar, self, value ) ctl_mstring_(tchar,grow, putfloat64 )((self),(value) )
00315
00323 #define ctl_gstring_putfloat64(tchar, self, value ) ctl_mstring_(tchar,grow, putfloat64 )((self),(value) )
00324
00332 #define ctl_gstring_putxint8(tchar, self, value ) ctl_mstring_(tchar,grow, putxuint32 )((self),(uint32)(value), 2 )
00333
00341 #define ctl_gstring_putxint16(tchar, self, value ) ctl_mstring_(tchar,grow, putxuint32 )((self),(uint32)(value), 4 )
00342
00350 #define ctl_gstring_putxint32(tchar, self, value ) ctl_mstring_(tchar,grow, putxuint32 )((self),(uint32)(value), 8 )
00351
00359 #define ctl_gstring_putxint64(tchar, self, value ) ctl_mstring_(tchar,grow, putxuint64 )((self),(uint32)(value), 16 )
00360
00368 #define ctl_gstring_putxuint8(tchar, self, value ) ctl_mstring_(tchar,grow, putxuint32 )((self),(uint32)(value), 2 )
00369
00377 #define ctl_gstring_putxuint16(tchar, self, value ) ctl_mstring_(tchar,grow, putxuint32 )((self),(value), 4 )
00378
00386 #define ctl_gstring_putxuint32(tchar, self, value ) ctl_mstring_(tchar,grow, putxuint32 )((self),(value), 8 )
00387
00395 #define ctl_gstring_putxuint64(tchar, self, value ) ctl_mstring_(tchar,grow, putxuint64 )((self),(value), 16 )
00396
00406 #define ctl_gstring_putenum(tchar, self, value, szzList, szUndefined ) ctl_mstring_(tchar,grow, putenum )((self),(value),(szzList), countof(szzList),(szUndefined) )
00407
00418 #define ctl_gstring_putenum_max(tchar, self, value, szzList, max, szUndefined ) ctl_mstring_(tchar,grow, putenum )((self),(value),(szzList), (max), (szUndefined) )
00419
00427 #define ctl_gstring_strcat(tchar, self, sz ) ctl_mstring_(tchar,grow, strncat )((self),(sz), ~0u )
00428
00436 #define ctl_gstring_strcpy(tchar, self, sz ) ctl_mstring_(tchar,grow, strncpy )((self),(sz), ~0u )
00437
00446 #define ctl_gstring_strncat(tchar, self, sz, maxLen ) ctl_mstring_(tchar,grow, strncat )((self),(sz),(maxLen) )
00447
00456 #define ctl_gstring_strncpy(tchar, self, sz, maxLen ) ctl_mstring_(tchar,grow, strncpy )((self),(sz),(maxLen) )
00457
00466 #define ctl_gstring_strinsert(tchar, self, position, sz ) ctl_mstring_(tchar,grow, strninsert )((self),(position),(sz), 0u )
00467
00477 #define ctl_gstring_strninsert(tchar, self, position, sz, maxLen ) ctl_mstring_(tchar,grow, strninsert )((self),(position),(sz),(maxLen) )
00478
00487 #define ctl_gstring_vsprintf(tchar, self, fmt, args ) ctl_mstring_(tchar,grow, vsprintf )((self),(fmt),(args) )
00488
00497 #define ctl_gstring_sprintf(tchar, selffmtargs ) ctl_mstring_(tchar,grow, sprintf ) selffmtargs
00498
00505 #define ctl_gstring_makeClabel(tchar,self) ctl_mstring_(tchar,grow, makeClabel )( (self) )
00506
00514 #define ctl_gstring_truncate(tchar, self, newsize ) ctl_mstring_(tchar,grow, truncate )( (self), (newsize) )
00515
00524 #define ctl_gstring_compare(tchar, p1, p2 ) ctl_mstring_(tchar,grow, compare )( p1, p2 )
00525
00534 #define ctl_gstring_rcompare(tchar, p1, p2 ) ctl_mstring_(tchar,grow, rcompare )( p1, p2 )
00535
00536
00537 #define ctl_gstring_strncmp(tchar, p1, p2, lenp2 ) ctl_mstring_(tchar,grow, strncmp )( p1, p2, (lenp2) )
00538 #define ctl_gstring_strnicmp(tchar, p1, p2, lenp2 ) ctl_mstring_(tchar,grow, strnicmp )( p1, p2, (lenp2) )
00539 #define ctl_gstring_strcmp(tchar, p1, p2 ) ctl_mstring_(tchar,grow, strncmp )( p1, p2, ~0u )
00540 #define ctl_gstring_stricmp(tchar, p1, p2 ) ctl_mstring_(tchar,grow, strnicmp )( p1, p2, ~0u )
00541
00549 #define ctl_gstring_foreach(tchar,self,iterator) \
00550 tchar* iterator = (self)->begin;\
00551 tchar* ppConcat(end_,iterator) = (self)->end;\
00552 for( ; iterator < ppConcat(end_,iterator); ++iterator )
00553
00561 #define ctl_gstring_foreach_reverse(tchar,self,iterator) \
00562 tchar* iterator = (self)->end;\
00563 tchar* ppConcat(end_,iterator) = (self)->begin;\
00564 while( iterator-- < ppConcat(end_,iterator) )
00565
00566 #endif