diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2024-03-06 12:29:36 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2024-03-06 12:29:36 +0000 |
commit | 4a2abe7bf4c05db91093e4a2d29d27430316bc05 (patch) | |
tree | f2ef6b5b77d4ac0dfef4f317b0a520bba1d4e2e1 /src/libtipidee/tipidee_util_htmlescape.c | |
parent | 628b64629d17fef775838736a17ff43bcef8e471 (diff) | |
download | tipidee-4a2abe7bf4c05db91093e4a2d29d27430316bc05.tar.xz |
Add ls.cgi, prepare for 0.0.4.0
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee/tipidee_util_htmlescape.c')
-rw-r--r-- | src/libtipidee/tipidee_util_htmlescape.c | 38 |
1 files changed, 38 insertions, 0 deletions
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 <stdlib.h> + +#include <tipidee/util.h> + +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 ; +} |