From 5f20e1e731be95e892d7bc50cba64ca30f2d054d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 21 Feb 2010 12:44:00 +0000 Subject: [PATCH] * some doxygen grouping * add -tounixlf string converter --- libcitadel/lib/libcitadel.h | 1 + libcitadel/lib/stringbuf.c | 48 +++++++++++++++++++++++++------ libcitadel/tests/stringbuf_test.c | 7 +++-- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index a98162840..09cb3ef11 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -308,6 +308,7 @@ void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash); void StrBufEUid_unescapize(StrBuf *target, const StrBuf *source); void StrBufEUid_escapize(StrBuf *target, const StrBuf *source); +void StrBufToUnixLF(StrBuf *buf); void StrBufReplaceChars(StrBuf *buf, char search, char replace); int CompressBuffer(StrBuf *Buf); diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index aa768646a..5ded8753f 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -619,7 +619,7 @@ int StrBufIsNumber(const StrBuf *Buf) { return 0; } /** - * @ingroup StrBuf + * @ingroup StrBuf_Filler * @brief modifies a Single char of the Buf * You can point to it via char* or a zero-based integer * @param Buf The buffer to manipulate @@ -640,7 +640,7 @@ long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue) } /** - * @ingroup StrBuf + * @ingroup StrBuf_Filler * @brief Append a StringBuffer to the buffer * @param Buf Buffer to modify * @param AppendBuf Buffer to copy at the end of our buffer @@ -665,7 +665,7 @@ void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, unsigned long Offset) /** - * @ingroup StrBuf + * @ingroup StrBuf_Filler * @brief Append a C-String to the buffer * @param Buf Buffer to modify * @param AppendBuf Buffer to copy at the end of our buffer @@ -697,7 +697,7 @@ void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, u } /** - * @ingroup StrBuf + * @ingroup StrBuf_Filler * @brief sprintf like function appending the formated string to the buffer * vsnprintf version to wrap into own calls * @param Buf Buffer to extend by format and Params @@ -740,7 +740,7 @@ void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap) } /** - * @ingroup StrBuf + * @ingroup StrBuf_Filler * @brief sprintf like function appending the formated string to the buffer * @param Buf Buffer to extend by format and Params * @param format printf alike format to add @@ -781,7 +781,7 @@ void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...) } /** - * @ingroup StrBuf + * @ingroup StrBuf_Filler * @brief sprintf like function putting the formated string into the buffer * @param Buf Buffer to extend by format and Parameters * @param format printf alike format to add @@ -809,7 +809,7 @@ void StrBufPrintf(StrBuf *Buf, const char *format, ...) } /** - * @ingroup StrBuf + * @ingroup StrBuf_Filler * @brief Callback for cURL to append the webserver reply to a buffer * @param ptr pre-defined by the cURL API; see man 3 curl for mre info * @param size pre-defined by the cURL API; see man 3 curl for mre info @@ -944,7 +944,7 @@ void StrBufTrim(StrBuf *Buf) } /** - * @ingroup StrBuf + * @ingroup StrBuf_Filler * @brief uppercase the contents of a buffer * @param Buf the buffer to translate */ @@ -964,7 +964,7 @@ void StrBufUpCase(StrBuf *Buf) /** - * @ingroup StrBuf + * @ingroup StrBuf_Filler * @brief lowercase the contents of a buffer * @param Buf the buffer to translate */ @@ -2349,6 +2349,36 @@ void StrBufReplaceChars(StrBuf *buf, char search, char replace) } +/** + * @ingroup StrBuf + * @brief removes all \r s from the string, or replaces them with \n if its not a combination of both. + * @param buf Buffer to modify + */ +void StrBufToUnixLF(StrBuf *buf) +{ + char *pche, *pchS, *pchT; + if (buf == NULL) + return; + + pche = buf->buf + buf->BufUsed; + pchS = pchT = buf->buf; + while (pchS < pche) + { + if (*pchS == '\r') + { + pchS ++; + if (*pchS != '\n') { + *pchT = '\n'; + pchT++; + } + } + *pchT = *pchS; + pchT++; pchS++; + } + *pchT = '\0'; + buf->BufUsed = pchT - buf->buf; +} + /******************************************************************************* * Iconv Wrapper; RFC822 de/encoding * diff --git a/libcitadel/tests/stringbuf_test.c b/libcitadel/tests/stringbuf_test.c index 209bc98e5..84d79279d 100644 --- a/libcitadel/tests/stringbuf_test.c +++ b/libcitadel/tests/stringbuf_test.c @@ -204,6 +204,7 @@ static void TestBufNumbers(void) CU_ASSERT(strlen(ch) == i); free(ch); FreeStrBuf(&Buf2); + FreeStrBuf(&Buf3); } static void TestStrBufPeek(void) @@ -233,6 +234,7 @@ static void TestStrBufPeek(void) CU_ASSERT(StrBufPeek(Buf, NULL, 5, 'A') == 5); CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123AA6"); + FreeStrBuf(&Buf); } static void TestBufStringManipulation(void) @@ -624,6 +626,7 @@ static void AddStrBufSimpleTests(void) int main(int argc, char* argv[]) { + int i; setvbuf(stdout, NULL, _IONBF, 0); StartLibCitadel(8); @@ -631,7 +634,7 @@ int main(int argc, char* argv[]) if (argc > 0) Quiet = 1; // todo: -q ;-) - + for (i=0; i< 100000; i++) { CU_set_output_filename("TestAutomated"); if (CU_initialize_registry()) { printf("\nInitialize of test Registry failed."); @@ -648,6 +651,6 @@ int main(int argc, char* argv[]) } CU_cleanup_registry(); - + } return 0; } -- 2.39.2