From 54ba2ed5462c8df35037a377398b05d1e8c0dcd9 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sun, 17 Feb 2013 15:50:46 +0100 Subject: [PATCH] Add new function to remove non-ascii characters from strings. --- libcitadel/lib/libcitadel.h | 1 + libcitadel/lib/stringbuf.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) 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 -- 2.30.2