* some doxygen grouping
authorWilfried Göesgens <willi@citadel.org>
Sun, 21 Feb 2010 12:44:00 +0000 (12:44 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 21 Feb 2010 12:44:00 +0000 (12:44 +0000)
* add -tounixlf string converter

libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c
libcitadel/tests/stringbuf_test.c

index a981628406f7b00ccf0f348de36153889053a71a..09cb3ef11da9ec1e2dc3df0aa843c7fc8ee85309 100644 (file)
@@ -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);
index aa768646a7a52d747d935891a3234dcec766cdcd..5ded8753fa828463eabe2e8d894d72e1e109f315 100644 (file)
@@ -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                           *
index 209bc98e503923cb83a7412ac93ba66d2e13f696..84d79279d4e03c3aa5e578d925ba69f4f09213a8 100644 (file)
@@ -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;
 }