/****************************************************************************** * SWBuf::append - appends a value to the current value of this SWBuf * */ void SWBuf::append(const char *str, long max) { // if (!str) //A null string was passed // return; if (max < 0) max = strlen(str); assureMore(max+1); for (;((max)&&(*str));max--) *end++ = *str++; *end = 0; }
/****************************************************************************** * SWBuf::appendFormatted - appends formatted strings to the current value of this SWBuf * WARNING: This function can only write at most * JUNKBUFSIZE to the string per call. */ void SWBuf::appendFormatted(const char *format, ...) { va_list argptr; va_start(argptr, format); #ifdef NO_VSNPRINTF int len = vsprintf(junkBuf, format, argptr)+1; #else int len = vsnprintf(0, 0, format, argptr)+1; #endif va_end(argptr); assureMore(len); va_start(argptr, format); end += vsprintf(end, format, argptr); va_end(argptr); }
/****************************************************************************** * SWBuf::appendFormatted - appends formatted strings to the current value of this SWBuf * WARNING: This function can only write at most * JUNKBUFSIZE to the string per call. */ SWBuf &SWBuf::appendFormatted(const char *format, ...) { va_list argptr; va_start(argptr, format); #ifdef NO_VSNPRINTF static char junkBuf[JUNKBUFSIZE]; int len = vsprintf(junkBuf, format, argptr)+1; #else int len = vsnprintf(0, 0, format, argptr)+1; #endif va_end(argptr); assureMore(len); va_start(argptr, format); end += vsprintf(end, format, argptr); va_end(argptr); return *this; }
void SWBuf::insert(unsigned long pos, const char* str, unsigned long start, signed long max) { // if (!str) //A null string was passed // return; str += start; int len = (max > -1) ? max : strlen(str); if (!len || (pos > length())) //nothing to do, return return; // pos==length(), so we can call append in this case if (pos == length()) { //append is more efficient append(str, max); return; } assureMore( len ); memmove(buf + pos + len, buf + pos, (end - buf) - pos); //make a gap of "len" bytes memcpy(buf+pos, str, len); end += len; *end = 0; }