inc/dystring.h

Go to the documentation of this file.
00001 /* dystring - dynamically resizing string. 
00002  *
00003  * This file is copyright 2002 Jim Kent, but license is hereby
00004  * granted for all use - public, private or commercial. */
00005 
00006 #ifndef DYSTRING_H      /* Wrapper to avoid including this twice. */
00007 #define DYSTRING_H
00008 
00009 struct dyString
00010 /* Dynamically resizable string that you can do formatted
00011  * output to. */
00012     {
00013     struct dyString *next;      /* Next in list. */
00014     char *string;               /* Current buffer. */
00015     int bufSize;                /* Size of buffer. */
00016     int stringSize;             /* Size of string. */
00017     };
00018 
00019 struct dyString *newDyString(int initialBufSize);
00020 /* Allocate dynamic string with initial buffer size.  (Pass zero for default) */
00021 
00022 #define dyStringNew newDyString
00023 
00024 void freeDyString(struct dyString **pDs);
00025 /* Free up dynamic string. */
00026 
00027 #define dyStringFree(a) freeDyString(a);
00028 
00029 void freeDyStringList(struct dyString **pDs);
00030 /* Free up a list of dynamic strings */
00031 
00032 #define dyStringFreeList(a) freeDyStringList(a);
00033 
00034 void dyStringAppend(struct dyString *ds, char *string);
00035 /* Append zero terminated string to end of dyString. */
00036 
00037 void dyStringAppendN(struct dyString *ds, char *string, int stringSize);
00038 /* Append string of given size to end of string. */
00039 
00040 char dyStringAppendC(struct dyString *ds, char c);
00041 /* Append char to end of string. */ 
00042 
00043 void dyStringAppendMultiC(struct dyString *ds, char c, int n);
00044 /* Append N copies of char to end of string. */ 
00045 
00046 void dyStringAppendEscapeQuotes(struct dyString *dy, char *string, 
00047         char quot, char esc);
00048 /* Append escaped-for-quotation version of string to dy. */
00049 
00050 void dyStringVaPrintf(struct dyString *ds, char *format, va_list args);
00051 /* VarArgs Printf to end of dyString. */
00052 
00053 void dyStringPrintf(struct dyString *ds, char *format, ...)
00054 /*  Printf to end of dyString. */
00055 #ifdef __GNUC__
00056 __attribute__((format(printf, 2, 3)))
00057 #endif
00058     ;
00059 
00060 #define dyStringClear(ds) (ds->string[0] = ds->stringSize = 0)
00061 /* Clear string. */
00062 
00063 struct dyString * dyStringSub(char *orig, char *in, char *out);
00064 /* Make up a duplicate of orig with all occurences of in substituted
00065  * with out. */
00066 
00067 void dyStringBumpBufSize(struct dyString *ds, int size);
00068 /* Force dyString buffer to be at least given size. */
00069 
00070 char *dyStringCannibalize(struct dyString **pDy);
00071 /* Kill dyString, but return the string it is wrapping
00072  * (formerly dy->string).  This should be free'd at your
00073  * convenience. */
00074 
00075 void dyStringResize(struct dyString *ds, int newSize);
00076 /* resize a string, if the string expands, blanks are appended */
00077 
00078 #endif /* DYSTRING_H */
00079 

Generated on Tue Dec 25 18:39:29 2007 for blat by  doxygen 1.5.2