diff options
-rw-r--r-- | doc.c | 4 | ||||
-rw-r--r-- | doc.h | 3 | ||||
-rw-r--r-- | parse.c | 22 |
3 files changed, 14 insertions, 15 deletions
diff --git a/doc.c b/doc.c index 38b4802..97d8b34 100644 --- a/doc.c +++ b/doc.c @@ -38,8 +38,8 @@ void doc_new_line(struct doc *d) { d->txt.sz += sizeof(struct doc_line); } -void doc_add_line(struct doc *d, const char *s) { - doc_add_text(d, s); +void doc_add_line(struct doc *d, strv_t s) { + doc_add_textn(d, s.s, s.n); doc_new_line(d); } diff --git a/doc.h b/doc.h index 132999e..a71ca49 100644 --- a/doc.h +++ b/doc.h @@ -2,6 +2,7 @@ #define DOC_H #include "buf.h" +#include "strv.h" #define DOC_LINK_NONE 0xffff @@ -27,7 +28,7 @@ void doc_init(struct doc *); void doc_fini(struct doc *); void doc_new_line(struct doc *); -void doc_add_line(struct doc *, const char *); +void doc_add_line(struct doc *, strv_t); void doc_add_text(struct doc *, const char *); void doc_add_textn(struct doc *, const char *, size_t); 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; } |