From 320551762cb556df0b0796457b7e1456b920fd30 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sat, 29 Nov 2008 08:45:48 +0000 Subject: [PATCH] * new StrBuf Method: cut it at a given position --- libcitadel/lib/libcitadel.h | 1 + libcitadel/lib/stringbuf.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index a317898b5..59316a21f 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -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); diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index fb817d2f0..f5cfbbb37 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -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. -- 2.39.2