]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/stringbuf.c
* add a strbuf'ed version of stripslashes
[citadel.git] / libcitadel / lib / stringbuf.c
index 1af664ef1af1b4f7040d1449a175b8b01d286f81..8d665866ca05c478d2a14e064fc29822e3affff2 100644 (file)
@@ -1962,6 +1962,36 @@ void StrBufLowerCase(StrBuf *Buf)
        }
 }
 
+/**
+ * \Brief removes double slashes from pathnames
+ * \param Dir directory string to filter
+ * \param RemoveTrailingSlash allows / disallows trailing slashes
+ */
+void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash)
+{
+       char *a, *b;
+
+       a = b = Dir->buf;
+
+       while (!IsEmptyStr(a)) {
+               if (*a == '/') {
+                       while (*a == '/')
+                               a++;
+                       *b = '/';
+                       b++;
+               }
+               else {
+                       *b = *a;
+                       b++; a++;
+               }
+       }
+       if ((RemoveTrailingSlash) && (*(b - 1) != '/')){
+               *b = '/';
+               b++;
+       }
+       *b = '\0';
+       Dir->BufUsed = b - Dir->buf;
+}
 
 /**
  * \brief unhide special chars hidden to the HTML escaper