* add StrBufPook which blobs out a sub-part of the string
authorWilfried Göesgens <willi@citadel.org>
Sat, 13 Mar 2010 09:56:00 +0000 (09:56 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 13 Mar 2010 09:56:00 +0000 (09:56 +0000)
* add StrBufStripAllBut, which aims to replace stripallbut, whose functionality is not yet all clear to me.
* add NULL protection to StrBufSub

libcitadel/debian/changelog
libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c

index 89a20b553e9fe9aad208657a38c4993e56b5d3e4..9fce5cd2d7b96d542e2ff40a097ff0da165f89d8 100644 (file)
@@ -1,3 +1,9 @@
+libcitadel (7.79-87) unstable; urgency=low
+
+  * no new release yet.
+
+ -- Wilfried Goesgens <w.goesgens@outgesourced.org>  Tue, 16 Dec 2009 22:00:00 +0002
+
 libcitadel (7.70-86) unstable; urgency=low
 
   * new release
index 464edc34bb249e5cde95917542cb762a1ae87dfc..cc9893182ecb84f3fce2ce1c4dc0d0f9917d0ae4 100644 (file)
@@ -278,6 +278,7 @@ const char *ChrPtr(const StrBuf *Str);
 int StrLength(const StrBuf *Str);
 #define SKEY(a) ChrPtr(a), StrLength(a)
 long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue);
+long StrBufPook(StrBuf *Buf, const char* ptr, long nThChar, long nChars, char PookValue);
 
 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);
@@ -337,6 +338,7 @@ void StrBufCutLeft(StrBuf *Buf, int nChars);
 void StrBufCutRight(StrBuf *Buf, int nChars);
 void StrBufCutAt(StrBuf *Buf, int AfternChars, const char *At);
 void StrBufTrim(StrBuf *Buf);
+void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary);
 void StrBufUpCase(StrBuf *Buf);
 void StrBufLowerCase(StrBuf *Buf);
 void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash);
index 1e27edb45401313f0d02f39c5a7bbd24e67ac279..f0506886a4954df301132f4f440d306ddb10145b 100644 (file)
@@ -618,6 +618,7 @@ int StrBufIsNumber(const StrBuf *Buf) {
                return 0;
        return 0;
 } 
+
 /**
  * @ingroup StrBuf_Filler
  * @brief modifies a Single char of the Buf
@@ -639,6 +640,33 @@ long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue)
        return nThChar;
 }
 
+/**
+ * @ingroup StrBuf_Filler
+ * @brief modifies a range of chars of the Buf
+ * You can point to it via char* or a zero-based integer
+ * @param Buf The buffer to manipulate
+ * @param ptr char* to zero; use NULL if unused
+ * @param nThChar zero based pointer into the string; use -1 if unused
+ * @param nChars how many chars are to be flushed?
+ * @param PookValue The Character to place into that area
+ */
+long StrBufPook(StrBuf *Buf, const char* ptr, long nThChar, long nChars, char PookValue)
+{
+       if (Buf == NULL)
+               return -1;
+       if (ptr != NULL)
+               nThChar = ptr - Buf->buf;
+       if ((nThChar < 0) || (nThChar > Buf->BufUsed))
+               return -1;
+       if (nThChar + nChars > Buf->BufUsed)
+               nChars =  Buf->BufUsed - nThChar;
+
+       memset(Buf->buf + nThChar, PookValue, nChars);
+       /* just to be shure... */
+       Buf->buf[Buf->BufUsed] = 0;
+       return nChars;
+}
+
 /**
  * @ingroup StrBuf_Filler
  * @brief Append a StringBuffer to the buffer
@@ -844,7 +872,8 @@ int StrBufSub(StrBuf *dest, const StrBuf *Source, unsigned long Offset, size_t n
        size_t NCharsRemain;
        if (Offset > Source->BufUsed)
        {
-               FlushStrBuf(dest);
+               if (dest != NULL)
+                       FlushStrBuf(dest);
                return 0;
        }
        if (Offset + nChars < Source->BufUsed)
@@ -944,9 +973,34 @@ void StrBufTrim(StrBuf *Buf)
                delta ++;
        }
        if (delta > 0) StrBufCutLeft(Buf, delta);
+}
+
+void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary)
+{
+       const char *pBuff;
+       const char *pLeft;
+       const char *pRight;
 
+       if (Buf == NULL)
+               return;
+       pLeft = pBuff = Buf->buf;
+       while (pBuff != NULL) {
+               pLeft = pBuff;
+               pBuff = strchr(pBuff, leftboundary);
+       }
+               
+       if (pLeft != NULL)
+               pBuff = pLeft;
+       else
+               pBuff = Buf->buf;
+       pRight = strchr(pBuff, rightboundary);
+       if (pRight != NULL)
+               StrBufCutAt(Buf, 0, pRight - 1);
+       if (pLeft != NULL)
+               StrBufCutLeft(Buf, pLeft - Buf->buf + 1);
 }
 
+
 /**
  * @ingroup StrBuf_Filler
  * @brief uppercase the contents of a buffer