summary refs log tree commit diff
path: root/parse.c
diff options
context:
space:
mode:
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;
 }