summary refs log tree commit diff
path: root/parse.c
diff options
context:
space:
mode:
authorwrmr2024-11-08 23:23:07 -0500
committerwrmr2024-11-08 23:23:07 -0500
commit6050dcdd3669b7102f35a226a6a3ee485c7b703a (patch)
tree68c710564085c9bdf3fabc4da5663f72e119b72f /parse.c
parent25cde1651b86455707051a842ed66a6df59a006b (diff)
use strv_t in plaintext parsing, doc_add_line
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c22
1 files changed, 10 insertions, 12 deletions
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;
 }