#include <swbuf.h>

Public Member Functions | |
| void | append (wchar_t wch) |
| void | append (char ch) |
| void | append (const SWBuf &str, long max=-1) |
| void | append (const char *str, long max=-1) |
| void | appendFormatted (const char *format,...) |
| const char * | c_str () const |
| char & | charAt (unsigned long pos) |
| int | compare (const char *other) const |
| int | compare (const SWBuf &other) const |
| bool | endsWith (const char *postfix) const |
| bool | endsWith (const SWBuf &postfix) const |
| char | getFillByte () |
| char * | getRawData () |
| long | indexOf (const SWBuf &needle) const |
| void | insert (unsigned long pos, char c) |
| void | insert (unsigned long pos, const SWBuf &str, unsigned long start=0, signed long max=-1) |
| void | insert (unsigned long pos, const char *str, unsigned long start=0, signed long max=-1) |
| unsigned long | length () const |
| operator const char * () const | |
| bool | operator!= (const char *other) const |
| bool | operator!= (const SWBuf &other) const |
| SWBuf | operator+ (char ch) const |
| SWBuf | operator+ (const SWBuf &other) const |
| SWBuf & | operator+= (char ch) |
| SWBuf & | operator+= (const char *str) |
| SWBuf & | operator-- (int) |
| SWBuf & | operator-= (unsigned long len) |
| bool | operator< (const char *other) const |
| bool | operator< (const SWBuf &other) const |
| SWBuf & | operator<< (unsigned long n) |
| bool | operator<= (const char *other) const |
| bool | operator<= (const SWBuf &other) const |
| SWBuf & | operator= (const SWBuf &other) |
| SWBuf & | operator= (const char *newVal) |
| bool | operator== (const char *other) const |
| bool | operator== (const SWBuf &other) const |
| bool | operator> (const char *other) const |
| bool | operator> (const SWBuf &other) const |
| bool | operator>= (const char *other) const |
| bool | operator>= (const SWBuf &other) const |
| SWBuf & | operator>> (unsigned long n) |
| char & | operator[] (int pos) |
| char & | operator[] (unsigned int pos) |
| char & | operator[] (long pos) |
| char & | operator[] (unsigned long pos) |
| SWBuf & | replaceBytes (const char *targets, char newByte) |
| void | resize (unsigned long len) |
| void | set (const char *newVal) |
| void | set (const SWBuf &newVal) |
| void | setFillByte (char ch) |
| SWBuf & | setFormatted (const char *format,...) |
| void | setSize (unsigned long len) |
| void | size (unsigned long newSize) |
| unsigned long | size () const |
| bool | startsWith (const char *prefix) const |
| bool | startsWith (const SWBuf &prefix) const |
| const char * | stripPrefix (char separator, bool endOfStringAsSeparator=false) |
| SWBuf (const SWBuf &other, unsigned long initSize=0) | |
| SWBuf (char initVal, unsigned long initSize=0) | |
| SWBuf (const char *initVal, unsigned long initSize=0) | |
| SWBuf () | |
| SWBuf & | trim () |
| SWBuf & | trimEnd () |
| SWBuf & | trimStart () |
| ~SWBuf () | |
Private Member Functions | |
| void | assureMore (size_t pastEnd) |
| void | assureSize (size_t checkSize) |
| void | init (size_t initSize) |
Private Attributes | |
| unsigned long | allocSize |
| char * | buf |
| char * | end |
| char * | endAlloc |
| char | fillByte |
Static Private Attributes | |
| static char | junkBuf [JUNKBUFSIZE] |
| static char * | nullStr = (char *)"" |
This class is used as a transport and utility for data buffers.
Definition at line 44 of file swbuf.h.
| SWBuf::SWBuf | ( | const char * | initVal, | |
| unsigned long | initSize = 0 | |||
| ) |
| SWBuf::SWBuf | ( | char | initVal, | |
| unsigned long | initSize = 0 | |||
| ) |
| SWBuf::SWBuf | ( | const SWBuf & | other, | |
| unsigned long | initSize = 0 | |||
| ) |
| SWBuf::~SWBuf | ( | ) | [inline] |
| void SWBuf::append | ( | wchar_t | wch | ) | [inline] |
SWBuf::append - appends a wide charachter value to the current value of this SWBuf If the allocated memory is not enough, it will be resized accordingly. NOTE: This is dangerous, as wchar_t is currently different sizes on different platforms (stupid windoze; stupid c++ spec for not mandating 4byte).
| ch | Append this. |
Definition at line 263 of file swbuf.h.
00263 { 00264 assureMore(sizeof(wchar_t)*2); 00265 for (unsigned int i = 0; i < sizeof(wchar_t); i++) *end++ = ((char *)&wch)[i]; 00266 for (unsigned int i = 0; i < sizeof(wchar_t); i++) end[i] = 0; 00267 }
| void SWBuf::append | ( | char | ch | ) | [inline] |
SWBuf::append - appends a value to the current value of this SWBuf If the allocated memory is not enough, it will be resized accordingly.
| ch | Append this. |
Definition at line 250 of file swbuf.h.
00250 { 00251 assureMore(1); 00252 *end++ = ch; 00253 *end = 0; 00254 }
| void SWBuf::append | ( | const SWBuf & | str, | |
| long | max = -1 | |||
| ) | [inline] |
| void SWBuf::append | ( | const char * | str, | |
| long | max = -1 | |||
| ) |
SWBuf::append - appends a value to the current value of this SWBuf. If the allocated memory is not enough, it will be resized accordingly.
| str | Append this. | |
| max | Append only max chars. |
Definition at line 100 of file swbuf.cpp.
00100 { 00101 // if (!str) //A null string was passed 00102 // return; 00103 if (max < 0) 00104 max = strlen(str); 00105 assureMore(max+1); 00106 for (;((max)&&(*str));max--) 00107 *end++ = *str++; 00108 *end = 0; 00109 }
| void SWBuf::appendFormatted | ( | const char * | format, | |
| ... | ||||
| ) |
SWBuf::appendFormatted - appends formatted strings to the current value of this SWBuf.
| format | The format string. Same syntax as printf, for example. | |
| ... | Add all arguments here. |
Definition at line 127 of file swbuf.cpp.
00127 { 00128 va_list argptr; 00129 00130 va_start(argptr, format); 00131 #ifdef NO_VSNPRINTF 00132 int len = vsprintf(junkBuf, format, argptr)+1; 00133 #else 00134 int len = vsnprintf(0, 0, format, argptr)+1; 00135 #endif 00136 va_end(argptr); 00137 assureMore(len); 00138 va_start(argptr, format); 00139 end += vsprintf(end, format, argptr); 00140 va_end(argptr); 00141 }
| void SWBuf::assureMore | ( | size_t | pastEnd | ) | [inline, private] |
| void SWBuf::assureSize | ( | size_t | checkSize | ) | [inline, private] |
Definition at line 59 of file swbuf.h.
00059 { 00060 if (checkSize > allocSize) { 00061 long size = (end - buf); 00062 checkSize += 128; 00063 buf = (char *)((allocSize) ? realloc(buf, checkSize) : malloc(checkSize)); 00064 allocSize = checkSize; 00065 end = (buf + size); 00066 *end = 0; 00067 endAlloc = buf + allocSize - 1; 00068 } 00069 }
| const char* SWBuf::c_str | ( | ) | const [inline] |
| char& SWBuf::charAt | ( | unsigned long | pos | ) | [inline] |
| int SWBuf::compare | ( | const char * | other | ) | const [inline] |
| int SWBuf::compare | ( | const SWBuf & | other | ) | const [inline] |
| bool SWBuf::endsWith | ( | const char * | postfix | ) | const [inline] |
| bool SWBuf::endsWith | ( | const SWBuf & | postfix | ) | const [inline] |
| char SWBuf::getFillByte | ( | ) | [inline] |
SWBuf::getFillByte - Get the fillByte character
Definition at line 135 of file swbuf.h.
00135 { return fillByte; }
| char* SWBuf::getRawData | ( | ) | [inline] |
| long SWBuf::indexOf | ( | const SWBuf & | needle | ) | const [inline] |
| void SWBuf::init | ( | size_t | initSize | ) | [inline, private] |
| void SWBuf::insert | ( | unsigned long | pos, | |
| char | c | |||
| ) | [inline] |
SWBuf::insert - inserts the given character at position into this string
| pos | The position where to insert. pos=0 inserts at the beginning, pos=1 after the first char, etc. Using pos=length() is the same as calling append(s) | |
| c | Insert this. |
| void SWBuf::insert | ( | unsigned long | pos, | |
| const SWBuf & | str, | |||
| unsigned long | start = 0, |
|||
| signed long | max = -1 | |||
| ) | [inline] |
SWBuf::insert - inserts the given string at position into this string
| pos | The position where to insert. pos=0 inserts at the beginning, pos=1 after the first char, etc. Using pos=length() is the same as calling append(s) | |
| str | string to be inserted | |
| start | start from this position in the string to be inserted | |
| max | Insert only max chars. |
| void SWBuf::insert | ( | unsigned long | pos, | |
| const char * | str, | |||
| unsigned long | start = 0, |
|||
| signed long | max = -1 | |||
| ) |
SWBuf::insert - inserts the given string at position into this string
| pos | The position where to insert. pos=0 inserts at the beginning, pos=1 after the first char, etc. Using pos=length() is the same as calling append(s) | |
| str | string to be inserted | |
| start | start from this position in the string to be inserted | |
| max | Insert only max chars. |
Definition at line 143 of file swbuf.cpp.
00143 { 00144 // if (!str) //A null string was passed 00145 // return; 00146 00147 str += start; 00148 int len = (max > -1) ? max : strlen(str); 00149 00150 if (!len || (pos > length())) //nothing to do, return 00151 return; 00152 00153 // pos==length(), so we can call append in this case 00154 if (pos == length()) { //append is more efficient 00155 append(str, max); 00156 return; 00157 } 00158 00159 assureMore( len ); 00160 00161 memmove(buf + pos + len, buf + pos, (end - buf) - pos); //make a gap of "len" bytes 00162 memcpy(buf+pos, str, len); 00163 00164 end += len; 00165 *end = 0; 00166 }
| unsigned long SWBuf::length | ( | ) | const [inline] |
| SWBuf::operator const char * | ( | ) | const [inline] |
| bool SWBuf::operator!= | ( | const char * | other | ) | const [inline] |
| bool SWBuf::operator!= | ( | const SWBuf & | other | ) | const [inline] |
| SWBuf SWBuf::operator+ | ( | char | ch | ) | const [inline] |
| SWBuf& SWBuf::operator+= | ( | char | ch | ) | [inline] |
| SWBuf& SWBuf::operator+= | ( | const char * | str | ) | [inline] |
| SWBuf& SWBuf::operator-- | ( | int | ) | [inline] |
Decrease the buffer size, discarding the last character
Definition at line 343 of file swbuf.h.
00343 { operator -=(1); return *this; }
| SWBuf& SWBuf::operator-= | ( | unsigned long | len | ) | [inline] |
| bool SWBuf::operator< | ( | const char * | other | ) | const [inline] |
| bool SWBuf::operator< | ( | const SWBuf & | other | ) | const [inline] |
| SWBuf& SWBuf::operator<< | ( | unsigned long | n | ) | [inline] |
| bool SWBuf::operator<= | ( | const char * | other | ) | const [inline] |
| bool SWBuf::operator<= | ( | const SWBuf & | other | ) | const [inline] |
| SWBuf& SWBuf::operator= | ( | const char * | newVal | ) | [inline] |
| bool SWBuf::operator== | ( | const char * | other | ) | const [inline] |
| bool SWBuf::operator== | ( | const SWBuf & | other | ) | const [inline] |
| bool SWBuf::operator> | ( | const char * | other | ) | const [inline] |
| bool SWBuf::operator> | ( | const SWBuf & | other | ) | const [inline] |
| bool SWBuf::operator>= | ( | const char * | other | ) | const [inline] |
| bool SWBuf::operator>= | ( | const SWBuf & | other | ) | const [inline] |
| SWBuf& SWBuf::operator>> | ( | unsigned long | n | ) | [inline] |
| char& SWBuf::operator[] | ( | int | pos | ) | [inline] |
| char& SWBuf::operator[] | ( | unsigned int | pos | ) | [inline] |
| char& SWBuf::operator[] | ( | long | pos | ) | [inline] |
| char& SWBuf::operator[] | ( | unsigned long | pos | ) | [inline] |
| SWBuf& SWBuf::replaceBytes | ( | const char * | targets, | |
| char | newByte | |||
| ) | [inline] |
Replace with a new byte value all occurances in this buffer of any byte value specified in a set
| targets | a set of bytes, any of which will be replaced | |
| newByte | value to use as replacement. |
Example: replaceBytes("abc", 'z'); // replaces all occurances of 'a', 'b', and 'c' with 'z'
| void SWBuf::resize | ( | unsigned long | len | ) | [inline] |
SWBuf::resize - Resize this buffer to a specific length.
| len | The new size of the buffer. One byte for the null will be added. |
| void SWBuf::set | ( | const char * | newVal | ) | [inline] |
SWBuf::set - sets this buf to a new value. If the allocated memory is bigger than the new string, it will NOT be resized.
| newVal | the value to set this buffer to. |
Definition at line 185 of file swbuf.h.
00185 { 00186 if (newVal) { 00187 unsigned long len = strlen(newVal) + 1; 00188 assureSize(len); 00189 memcpy(buf, newVal, len); 00190 end = buf + (len - 1); 00191 } 00192 else { 00193 assureSize(1); 00194 end = buf; 00195 *end = 0; 00196 } 00197 }
| void SWBuf::set | ( | const SWBuf & | newVal | ) | [inline] |
SWBuf::set - sets this buf to a new value If the allocated memory is bigger than the new string, it will NOT be resized.
| newVal | the value to set this buffer to. |
| void SWBuf::setFillByte | ( | char | ch | ) | [inline] |
| SWBuf & SWBuf::setFormatted | ( | const char * | format, | |
| ... | ||||
| ) |
SWBuf::setFormatted - sets this buf to a formatted string. If the allocated memory is bigger than the new string, it will NOT be resized.
| format | The format string. Same syntax as printf, for example. | |
| ... | Add all arguments here. |
Definition at line 79 of file swbuf.cpp.
00079 { 00080 va_list argptr; 00081 00082 va_start(argptr, format); 00083 #ifdef NO_VSNPRINTF 00084 int len = vsprintf(junkBuf, format, argptr)+1; 00085 #else 00086 int len = vsnprintf(0, 0, format, argptr)+1; 00087 #endif 00088 va_end(argptr); 00089 assureSize(len); 00090 va_start(argptr, format); 00091 end = vsprintf(buf, format, argptr) + buf; 00092 va_end(argptr); 00093 return *this; 00094 }
| void SWBuf::setSize | ( | unsigned long | len | ) |
SWBuf::setSize - Size this buffer to a specific length.
| len | The new size of the buffer. One byte for the null will be added. |
| void SWBuf::size | ( | unsigned long | newSize | ) | [inline] |
| unsigned long SWBuf::size | ( | ) | const [inline] |
| bool SWBuf::startsWith | ( | const char * | prefix | ) | const [inline] |
| bool SWBuf::startsWith | ( | const SWBuf & | prefix | ) | const [inline] |
| const char* SWBuf::stripPrefix | ( | char | separator, | |
| bool | endOfStringAsSeparator = false | |||
| ) | [inline] |
Strip a prefix from this buffer up to a separator byte. Returns the prefix and modifies this buffer, shifting left to remove prefix
| separator | to use (e.g. ':') | |
| endOfStringAsSeparator | - also count end of string as separator. this is useful for tokenizing entire string like: x|y|z if true it will also include 'z'. |
Definition at line 396 of file swbuf.h.
00396 { const char *m = strchr(buf, separator); if (!m && endOfStringAsSeparator) { if (*buf) { operator >>(1); *buf=0; end = buf; return buf + 1;} else return buf; } if (m) { int len = m-buf; char *hold = new char[len]; memcpy(hold, buf, len); *this << (len+1); memcpy(end+1, hold, len); delete [] hold; end[len+1] = 0; } return (m) ? end+1 : 0; } // safe. we know we don't actually realloc and shrink buffer when shifting, so we can place our return val at end.
| SWBuf& SWBuf::trim | ( | ) | [inline] |
| SWBuf& SWBuf::trimEnd | ( | ) | [inline] |
| SWBuf& SWBuf::trimStart | ( | ) | [inline] |
unsigned long SWBuf::allocSize [private] |
char* SWBuf::buf [private] |
char* SWBuf::end [private] |
char* SWBuf::endAlloc [private] |
char SWBuf::fillByte [private] |
char SWBuf::junkBuf [static, private] |
SWORD_NAMESPACE_START char * SWBuf::nullStr = (char *)"" [static, private] |
1.6.1