snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit b9e43acf21c0c7d7e2521e168316494b5afcf6c6
parent 2eac1c1925c679acad4ef54ac120f088a355c781
Author: Santtu Lakkala <inz@inz.fi>
Date:   Fri, 31 Jan 2025 16:07:25 +0200

Use standard function

Diffstat:
Mxs_html.h | 18+++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/xs_html.h b/xs_html.h @@ -52,36 +52,28 @@ xs_str *xs_html_encode(const char *str) { xs_str *s = xs_str_new(NULL); int o = 0; - const char *e = str + strlen(str); + const char *ec = "<>\"'&"; /* characters to escape */ for (;;) { - char *ec = "<>\"'&"; /* characters to escape */ - const char *q = e; int z; /* find the nearest happening of a char */ - while (*ec) { - char *m = memchr(str, *ec++, q - str); - if (m) - q = m; - } + z = strcspn(str, ec); /* copy string to here */ - z = q - str; s = xs_insert_m(s, o, str, z); o += z; /* if q points to the end, nothing more to do */ - if (q == e) + str += z; + if (*str == '\0') break; /* insert the escaped char */ char tmp[8]; - z = snprintf(tmp, sizeof(tmp), "&#%d;", *q); + z = snprintf(tmp, sizeof(tmp), "&#%d;", *str++); s = xs_insert_m(s, o, tmp, z); o += z; - - str = q + 1; } return s;