diff options
Diffstat (limited to 'src/libtipidee')
-rw-r--r-- | src/libtipidee/deps-lib/tipidee | 1 | ||||
-rw-r--r-- | src/libtipidee/tipidee_util_htmlescape.c | 38 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/libtipidee/deps-lib/tipidee b/src/libtipidee/deps-lib/tipidee index 33f9f2f..b0b2c08 100644 --- a/src/libtipidee/deps-lib/tipidee +++ b/src/libtipidee/deps-lib/tipidee @@ -42,6 +42,7 @@ tipidee_rql_read.o tipidee_uri_parse.o tipidee_util_chunked_read.o tipidee_util_defaulttext.o +tipidee_util_htmlescape.o tipidee_util_httpdate.o tipidee_util_parse_range.o -lskarnet 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 ; +} |