+ add linebreak to html linebreak converting to StrEscAppend if nolinebreaks == 2
authorWilfried Göesgens <willi@citadel.org>
Mon, 26 Jan 2009 23:25:02 +0000 (23:25 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 26 Jan 2009 23:25:02 +0000 (23:25 +0000)
libcitadel/lib/stringbuf.c

index de57379dacb99dfc535314b3789a8ac1f5e2ccc2..9b03a0e6c10fc89951a2099717c04eadb19841d4 100644 (file)
@@ -448,7 +448,8 @@ void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn)
  * \param Source       source buffer; set to NULL if you just have a C-String
  * \param PlainIn       Plain-C string to append; set to NULL if unused
  * \param nbsp         If nonzero, spaces are converted to non-breaking spaces.
- * \param nolinebreaks if set, linebreaks are removed from the string.
+ * \param nolinebreaks if set to 1, linebreaks are removed from the string.
+ *                      if set to 2, linebreaks are replaced by &ltbr/&gt
  */
 long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks)
 {
@@ -474,12 +475,12 @@ long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int
                return -1;
 
        bptr = Target->buf + Target->BufUsed;
-       eptr = Target->buf + Target->BufSize - 6; /* our biggest unit to put in...  */
+       eptr = Target->buf + Target->BufSize - 11; /* our biggest unit to put in...  */
 
        while (aptr < eiptr){
                if(bptr >= eptr) {
                        IncreaseBuf(Target, 1, -1);
-                       eptr = Target->buf + Target->BufSize - 6; 
+                       eptr = Target->buf + Target->BufSize - 11; /* our biggest unit to put in...  */
                        bptr = Target->buf + Target->BufUsed;
                }
                if (*aptr == '<') {
@@ -527,10 +528,17 @@ long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int
                        bptr += 6;
                        Target->BufUsed += 6;
                }
-               else if ((*aptr == '\n') && (nolinebreaks)) {
+               else if ((*aptr == '\n') && (nolinebreaks == 1)) {
                        *bptr='\0';     /* nothing */
                }
-               else if ((*aptr == '\r') && (nolinebreaks)) {
+               else if ((*aptr == '\n') && (nolinebreaks == 2)) {
+                       memcpy(bptr, "&lt;br/&gt;", 11);
+                       bptr += 11;
+                       Target->BufUsed += 11;
+               }
+
+
+               else if ((*aptr == '\r') && (nolinebreaks != 0)) {
                        *bptr='\0';     /* nothing */
                }
                else{