From cd3626642755359eecf64d05e3f9db3d8b00ed24 Mon Sep 17 00:00:00 2001 From: wrmr Date: Fri, 8 Nov 2024 23:30:42 -0500 Subject: use strv_t even more --- parse.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'parse.c') diff --git a/parse.c b/parse.c index b62ea8a..df416ac 100644 --- a/parse.c +++ b/parse.c @@ -10,16 +10,16 @@ int isurlch(char c) { } void parse_plain_url(struct doc *d, struct doc_line *l, size_t i) { - char url[l->len + 1]; size_t start = i - 1; while (start > 0 && isalpha(l->txt[start])) start--; if (!isalpha(l->txt[start])) start++; size_t end = i + 3; while (end < l->len && isurlch(l->txt[end])) end++; if (end == i + 3) return; - size_t urln = end - start; - memcpy(url, &l->txt[start], urln); - url[urln] = 0; + strv_t url = { + &l->txt[start], + end - start + }; l->link = doc_add_link(d, url); } @@ -75,8 +75,7 @@ int parse_gophermap_line(struct doc *d, strv_t ln) { if (urln < sizeof url) url[urln++] = '/'; if (urln < sizeof url) url[urln++] = bits.item_type; urln = scatss(url, urln, sizeof url, bits.sel); - url[urln] = 0; - doc_set_link(d, doc_add_link(d, url)); + doc_set_link(d, doc_add_link(d, (strv_t) { url, urln })); case 'i': doc_add_text(d, bits.dstr); doc_new_line(d); -- cgit 1.4.1-2-gfad0