* new StrBuf Method: cut it at a given position
authorWilfried Göesgens <willi@citadel.org>
Sat, 29 Nov 2008 08:45:48 +0000 (08:45 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 29 Nov 2008 08:45:48 +0000 (08:45 +0000)
libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c

index a317898b55b4199a1bf0a690724e1273cf5fe851..59316a21f795c636dada3aa4f41d0a1f7a5c899a 100644 (file)
@@ -255,6 +255,7 @@ void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap);
 void StrBufPrintf(StrBuf *Buf, const char *format, ...) __attribute__((__format__(__printf__,2,3)));
 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 StrBufUpCase(StrBuf *Buf);
 void StrBufLowerCase(StrBuf *Buf);
index fb817d2f0769d336e821f68fef08855fc3eefd76..f5cfbbb374866a2d6e45499e0334420db600d4c0 100644 (file)
@@ -1143,6 +1143,24 @@ void StrBufCutRight(StrBuf *Buf, int nChars)
        Buf->buf[Buf->BufUsed] = '\0';
 }
 
+/**
+ * \brief Cut the string after n Chars
+ * \param Buf Buffer to modify
+ * \param AfternChars after how many chars should we trunkate the string?
+ * \param At if non-null and points inside of our string, cut it there.
+ */
+void StrBufCutAt(StrBuf *Buf, int AfternChars, const char *At)
+{
+       if (At != NULL){
+               AfternChars = At - Buf->buf;
+       }
+
+       if ((AfternChars < 0) || (AfternChars >= Buf->BufUsed))
+               return;
+       Buf->BufUsed = AfternChars;
+       Buf->buf[Buf->BufUsed] = '\0';
+}
+
 
 /*
  * Strip leading and trailing spaces from a string; with premeasured and adjusted length.