* add a strbuf'ed version of stripslashes
authorWilfried Göesgens <willi@citadel.org>
Tue, 23 Jun 2009 10:52:42 +0000 (10:52 +0000)
committerWilfried Göesgens <willi@citadel.org>
Tue, 23 Jun 2009 10:52:42 +0000 (10:52 +0000)
libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c

index 2b05c2a1afc8302c2d3fa968cb5738c4f598ea1c..20e4a0a1ec72f20f38e020ff84b8c11614bdec63 100644 (file)
@@ -296,6 +296,7 @@ void StrBufCutAt(StrBuf *Buf, int AfternChars, const char *At);
 void StrBufTrim(StrBuf *Buf);
 void StrBufUpCase(StrBuf *Buf);
 void StrBufLowerCase(StrBuf *Buf);
+void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash);
 void StrBufEUid_unescapize(StrBuf *target, const StrBuf *source);
 void StrBufEUid_escapize(StrBuf *target, const StrBuf *source);
 
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