From: Wilfried Göesgens Date: Tue, 23 Jun 2009 10:52:42 +0000 (+0000) Subject: * add a strbuf'ed version of stripslashes X-Git-Tag: v7.86~1013 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=68afde528d31aac8b261f674165ed1df6f604bfd;p=citadel.git * add a strbuf'ed version of stripslashes --- diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 2b05c2a1a..20e4a0a1e 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -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); diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 1af664ef1..8d665866c 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -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