From 4a2abe7bf4c05db91093e4a2d29d27430316bc05 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 6 Mar 2024 12:29:36 +0000 Subject: Add ls.cgi, prepare for 0.0.4.0 Signed-off-by: Laurent Bercot --- src/libtipidee/tipidee_util_htmlescape.c | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/libtipidee/tipidee_util_htmlescape.c (limited to 'src/libtipidee/tipidee_util_htmlescape.c') diff --git a/src/libtipidee/tipidee_util_htmlescape.c b/src/libtipidee/tipidee_util_htmlescape.c new file mode 100644 index 0000000..1dfd552 --- /dev/null +++ b/src/libtipidee/tipidee_util_htmlescape.c @@ -0,0 +1,38 @@ +/* ISC license. */ + +#include + +#include + +struct htmlescape_s +{ + char c ; + char const *code ; +} ; + +static struct htmlescape_s const table[] = +{ + { .c = '\"', .code = """ }, + { .c = '&', .code = "&" }, + { .c = '\'', .code = "'" }, + { .c = '<', .code = "<" }, + { .c = '>', .code = ">" }, +} ; + +static int htmlescape_cmp (void const *a, void const *b) +{ + char aa = *((char const *)a) ; + char bb = ((struct htmlescape_s const *)b)->c ; + return aa < bb ? -1 : aa > bb ; +} + +char const *tipidee_util_htmlescape (char const *s) +{ + struct htmlescape_s const *p = bsearch( + s, + table, + sizeof(table) / sizeof(struct htmlescape_s), + sizeof(struct htmlescape_s), + &htmlescape_cmp) ; + return p ? p->code : s ; +} -- cgit v1.2.3