* New StrBufPeek function to replace a special char inside of the string
authorWilfried Göesgens <willi@citadel.org>
Sat, 16 Aug 2008 17:41:40 +0000 (17:41 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 16 Aug 2008 17:41:40 +0000 (17:41 +0000)
* New AppendPrintf function so if one doesn't want to use wprintf...

libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c

index 81415177d61e155687d062060f8329e5d1d4b7a0..2459e94703f54e1b44dd197b265978c7edad5f58 100644 (file)
@@ -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);
index e0840e2f45766385f367d5260137ee36fb9219ed..a20fb258e5760a369a697c84917d0e24a3c143c5 100644 (file)
@@ -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;