Add new function to remove non-ascii characters from strings.
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 17 Feb 2013 14:50:46 +0000 (15:50 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 17 Feb 2013 14:50:46 +0000 (15:50 +0100)
libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c

index 02b9c9a4755352b5e3fdedec9daac474e41fdc99..5d3520a7328ea86ac1597dc4e01d0e01665aec19 100644 (file)
@@ -207,6 +207,7 @@ int FLUSHStrBuf(StrBuf *buf); /* expensive but doesn't leave content behind for
 const char *ChrPtr(const StrBuf *Str);
 int StrLength(const StrBuf *Str);
 #define SKEY(a) ChrPtr(a), StrLength(a)
+void StrBufAsciify(StrBuf *Buf, const char repl);
 long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue);
 long StrBufPook(StrBuf *Buf, const char* ptr, long nThChar, long nChars, char PookValue);
 
index 9a889ba5e9612e31d65a1122ca58bb5857033a2f..ab9a1814887e4204d21c98572dd5b2eb44f2e83b 100644 (file)
@@ -2540,6 +2540,23 @@ long StrHtmlEcmaEscAppend(StrBuf *Target, const StrBuf *Source, const char *Plai
        return Target->BufUsed;
 }
 
+
+/**
+ * @ingroup StrBuf_DeEnCoder
+ * @brief replace all non-Ascii characters by another
+ * @param Buf buffer to inspect
+ * @param repl charater to stamp over non ascii chars
+ */
+void StrBufAsciify(StrBuf *Buf, const char repl)
+{
+       long offset;
+
+       for (offset = 0; offset < Buf->BufUsed; offset ++)
+               if (!isascii(Buf->buf[offset]))
+                       Buf->buf[offset] = repl;
+       
+}
+
 /**
  * @ingroup StrBuf_DeEnCoder
  * @brief unhide special chars hidden to the HTML escaper