From: Wilfried Göesgens Date: Sat, 16 Aug 2008 17:41:40 +0000 (+0000) Subject: * New StrBufPeek function to replace a special char inside of the string X-Git-Tag: v7.86~2034 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=5841c93fa909560c04b747fd23bccb9ffcef403d;p=citadel.git * New StrBufPeek function to replace a special char inside of the string * New AppendPrintf function so if one doesn't want to use wprintf... --- diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 81415177d..2459e9470 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -214,6 +214,7 @@ int FlushStrBuf(StrBuf *buf); inline const char *ChrPtr(const StrBuf *Str); inline int StrLength(const StrBuf *Str); +long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue); int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error); int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **Error); @@ -227,6 +228,7 @@ inline int StrBufNum_tokens(const StrBuf *source, char tok); void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, size_t Offset); void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, size_t Offset); +void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...); #ifdef SHOW_ME_VAPPEND_PRINTF /* so owe don't create an include depndency, this is just visible on demand. */ void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap); diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index e0840e2f4..a20fb258e 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -177,6 +177,19 @@ int StrToi(const StrBuf *Buf) return 0; } +long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue) +{ + if (Buf == NULL) + return -1; + if (ptr != NULL) + nThChar = ptr - Buf->buf; + if ((nThChar < 0) || (nThChar > Buf->BufUsed)) + return -1; + Buf->buf[nThChar] = PeekValue; + return nThChar; +} + + int StrBufPlain(StrBuf *Buf, const char* ptr, int nChars) { size_t Siz = Buf->BufSize; @@ -292,6 +305,28 @@ void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap) } } +void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...) +{ + size_t nWritten = Buf->BufSize + 1; + size_t Offset = Buf->BufUsed; + size_t newused = Offset + nWritten; + va_list arg_ptr; + + while (newused >= Buf->BufSize) { + va_start(arg_ptr, format); + nWritten = vsnprintf(Buf->buf + Offset, + Buf->BufSize - Offset, + format, arg_ptr); + va_end(arg_ptr); + newused = Offset + nWritten; + if (newused >= Buf->BufSize) + IncreaseBuf(Buf, 1, 0); + else + Buf->BufUsed = Offset + nWritten ; + + } +} + void StrBufPrintf(StrBuf *Buf, const char *format, ...) { size_t nWritten = Buf->BufSize + 1;