diff options
author | Dimitri van Heesch <dimitri@stack.nl> | 2012-01-10 21:15:46 (GMT) |
---|---|---|
committer | Dimitri van Heesch <dimitri@stack.nl> | 2012-01-10 21:15:46 (GMT) |
commit | fd8b446f8ae60e7d1dc259c6f5fe38c287377d19 (patch) | |
tree | ab92980b31825ec310269f7799b1076422132a3e /src/growbuf.h | |
parent | 8a65c23b74c33c38b4d1234e76cec74bd08cea69 (diff) | |
download | Doxygen-fd8b446f8ae60e7d1dc259c6f5fe38c287377d19.zip Doxygen-fd8b446f8ae60e7d1dc259c6f5fe38c287377d19.tar.gz Doxygen-fd8b446f8ae60e7d1dc259c6f5fe38c287377d19.tar.bz2 |
Release-1.7.6.1-20120110
Diffstat (limited to 'src/growbuf.h')
-rw-r--r-- | src/growbuf.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/growbuf.h b/src/growbuf.h new file mode 100644 index 0000000..6798692 --- /dev/null +++ b/src/growbuf.h @@ -0,0 +1,38 @@ +#ifndef GROWBUF_H +#define GROWBUF_H + +#include <stdlib.h> +#include <string.h> + +class GrowBuf +{ + public: + GrowBuf() : str(0), pos(0), len(0) {} + ~GrowBuf() { free(str); str=0; pos=0; len=0; } + void clear() { pos=0; } + void addChar(char c) { if (pos>=len) { len+=1024; str = (char*)realloc(str,len); } + str[pos++]=c; + } + void addStr(const char *s) { + int l=strlen(s); + if (pos+l>=len) { len+=l+1024; str = (char*)realloc(str,len); } + strcpy(&str[pos],s); + pos+=l; + } + void addStr(const char *s,int n) { + int l=strlen(s); + if (n<l) l=n; + if (pos+l>=len) { len+=l+1024; str = (char*)realloc(str,len); } + strncpy(&str[pos],s,n); + pos+=l; + } + const char *get() { return str; } + int getPos() const { return pos; } + char at(int i) const { return str[i]; } + private: + char *str; + int pos; + int len; +}; + +#endif |