From: Wilfried Goesgens Date: Sun, 17 Feb 2013 14:50:46 +0000 (+0100) Subject: Add new function to remove non-ascii characters from strings. X-Git-Tag: v8.20~106 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=54ba2ed5462c8df35037a377398b05d1e8c0dcd9 Add new function to remove non-ascii characters from strings. --- diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 02b9c9a47..5d3520a73 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -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); diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 9a889ba5e..ab9a18148 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -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