summaryrefslogtreecommitdiffstats
path: root/src/growbuf.h
diff options
context:
space:
mode:
authorDimitri van Heesch <dimitri@stack.nl>2013-04-02 19:27:49 (GMT)
committerDimitri van Heesch <dimitri@stack.nl>2013-04-02 19:27:49 (GMT)
commitebf4b3641c9149eaf4468aa8df64e1c7517e5f0c (patch)
tree23804fcf753b3487b9a1ea28d4d28b71fa4ae208 /src/growbuf.h
parentdeaa34e0c1d990f37fe00e465ac7a22f705904f0 (diff)
downloadDoxygen-ebf4b3641c9149eaf4468aa8df64e1c7517e5f0c.zip
Doxygen-ebf4b3641c9149eaf4468aa8df64e1c7517e5f0c.tar.gz
Doxygen-ebf4b3641c9149eaf4468aa8df64e1c7517e5f0c.tar.bz2
Release-1.8.3.1-20130402
Diffstat (limited to 'src/growbuf.h')
-rw-r--r--src/growbuf.h28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/growbuf.h b/src/growbuf.h
index f1bf315..bc8e4b5 100644
--- a/src/growbuf.h
+++ b/src/growbuf.h
@@ -4,6 +4,8 @@
#include <stdlib.h>
#include <string.h>
+#define GROW_AMOUNT 1024
+
/** Class representing a string buffer optimised for growing. */
class GrowBuf
{
@@ -11,21 +13,27 @@ class GrowBuf
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); }
+ void addChar(char c) { if (pos>=len) { len+=GROW_AMOUNT; 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;
+ if (s)
+ {
+ int l=strlen(s);
+ if (pos+l>=len) { len+=l+GROW_AMOUNT; 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;
+ if (s)
+ {
+ int l=strlen(s);
+ if (n<l) l=n;
+ if (pos+l>=len) { len+=l+GROW_AMOUNT; str = (char*)realloc(str,len); }
+ strncpy(&str[pos],s,n);
+ pos+=l;
+ }
}
const char *get() { return str; }
int getPos() const { return pos; }