summaryrefslogtreecommitdiffstats
path: root/src/growbuf.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/growbuf.h')
-rw-r--r--src/growbuf.h52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/growbuf.h b/src/growbuf.h
index 2d0d503..cd6a67b 100644
--- a/src/growbuf.h
+++ b/src/growbuf.h
@@ -10,49 +10,49 @@
class GrowBuf
{
public:
- GrowBuf() : str(0), pos(0), len(0) {}
- GrowBuf(int initialSize) : pos(0), len(initialSize) { str=(char*)malloc(len); }
- ~GrowBuf() { free(str); str=0; pos=0; len=0; }
- void clear() { pos=0; }
- void addChar(char c) { if (pos>=len) { len+=GROW_AMOUNT; str = (char*)realloc(str,len); }
- str[pos++]=c;
+ GrowBuf() : m_str(0), m_pos(0), m_len(0) {}
+ GrowBuf(uint initialSize) : m_pos(0), m_len(initialSize) { m_str=(char*)malloc(m_len); }
+ ~GrowBuf() { free(m_str); }
+ void clear() { m_pos=0; }
+ void addChar(char c) { if (m_pos>=m_len) { m_len+=GROW_AMOUNT; m_str = (char*)realloc(m_str,m_len); }
+ m_str[m_pos++]=c;
}
void addStr(const QCString &s) {
if (!s.isEmpty())
{
- int l=s.length();
- if (pos+l>=len) { len+=l+GROW_AMOUNT; str = (char*)realloc(str,len); }
- strcpy(&str[pos],s.data());
- pos+=l;
+ uint l=s.length();
+ if (m_pos+l>=m_len) { m_len+=l+GROW_AMOUNT; m_str = (char*)realloc(m_str,m_len); }
+ strcpy(&m_str[m_pos],s.data());
+ m_pos+=l;
}
}
void addStr(const char *s) {
if (s)
{
- int l=(int)strlen(s);
- if (pos+l>=len) { len+=l+GROW_AMOUNT; str = (char*)realloc(str,len); }
- strcpy(&str[pos],s);
- pos+=l;
+ uint l=(uint)strlen(s);
+ if (m_pos+l>=m_len) { m_len+=l+GROW_AMOUNT; m_str = (char*)realloc(m_str,m_len); }
+ strcpy(&m_str[m_pos],s);
+ m_pos+=l;
}
}
- void addStr(const char *s,int n) {
+ void addStr(const char *s,uint n) {
if (s)
{
- int l=(int)strlen(s);
+ uint l=(uint)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;
+ if (m_pos+l>=m_len) { m_len+=l+GROW_AMOUNT; m_str = (char*)realloc(m_str,m_len); }
+ strncpy(&m_str[m_pos],s,n);
+ m_pos+=l;
}
}
- const char *get() { return str; }
- int getPos() const { return pos; }
- void setPos(const int newPos) { pos = newPos; }
- char at(int i) const { return str[i]; }
+ const char *get() { return m_str; }
+ uint getPos() const { return m_pos; }
+ void setPos(uint newPos) { m_pos = newPos; }
+ char at(uint i) const { return m_str[i]; }
private:
- char *str;
- int pos;
- int len;
+ char *m_str;
+ uint m_pos;
+ uint m_len;
};
#endif