From 6050dcdd3669b7102f35a226a6a3ee485c7b703a Mon Sep 17 00:00:00 2001 From: wrmr Date: Fri, 8 Nov 2024 23:23:07 -0500 Subject: use strv_t in plaintext parsing, doc_add_line --- parse.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'parse.c') diff --git a/parse.c b/parse.c index b6fedd1..ff0c973 100644 --- a/parse.c +++ b/parse.c @@ -25,20 +25,18 @@ void parse_plain_url(struct doc *d, struct doc_line *l, size_t i) { int parse_plain(struct doc *d, const buf_t *b) { doc_init(d); - for (size_t i = 0; i < b->sz; i++) { - char c = b->buf[i]; - if (c == '\n') { - struct doc_line *l = doc_line_at(d, d->latest); - for (size_t i = 1; i + 2 < l->len; i++) { - if (l->txt[i] == ':' && l->txt[i + 1] == '/' && l->txt[i + 2] == '/') { - parse_plain_url(d, l, i); - break; - } + strv_t buf = (strv_t) { b->buf, b->sz }; + size_t i = 0; + while (i < buf.n) { + strv_t ln = strv_head(buf, '\n', &i); + struct doc_line *l = doc_line_at(d, d->latest); + for (size_t j = 1; j + 2 < ln.n; j++) { + if (ln.s[j] == ':' && ln.s[j + 1] == '/' && ln.s[j + 2] == '/') { + parse_plain_url(d, l, j); + break; } - doc_new_line(d); - } else { - doc_add_textn(d, &c, 1); } + doc_add_line(d, ln); } return 0; } -- cgit 1.4.1-2-gfad0