diff options
-rw-r--r-- | parse.c | 3 | ||||
-rw-r--r-- | str.c | 9 | ||||
-rw-r--r-- | str.h | 1 |
3 files changed, 12 insertions, 1 deletions
diff --git a/parse.c b/parse.c index afa8008..7af7e52 100644 --- a/parse.c +++ b/parse.c @@ -27,6 +27,7 @@ int parse_plain(struct doc *d, const str_t *b) { doc_init(d); strv_t ln, buf = (strv_t) { b->buf, b->sz }; while (strv_split(&buf, '\n', &ln)) { + if (ln.n > 0 && ln.s[ln.n - 1] == '\r') ln.n--; 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] == '/') { @@ -58,7 +59,7 @@ int parse_gophermap_line(struct doc *d, strv_t ln) { strv_t host; strv_t port; } bits; - bits.item_type = *(ln.s++); ln.n++; + bits.item_type = strv_next(&ln); strv_split(&ln, '\t', &bits.dstr); strv_split(&ln, '\t', &bits.sel); strv_split(&ln, '\t', &bits.host); diff --git a/str.c b/str.c index 10d64e1..e0ea194 100644 --- a/str.c +++ b/str.c @@ -58,3 +58,12 @@ int strv_split(strv_t *src, int chr, strv_t *dest) { src->n -= dest->n + !!c; return dest->n > 0; } + +char strv_next(strv_t *s) { + if (s->n > 0) { + s->n--; + return *(s->s++); + } else { + return 0; + } +} diff --git a/str.h b/str.h index fe56d98..a078cfd 100644 --- a/str.h +++ b/str.h @@ -11,6 +11,7 @@ typedef struct { } strv_t; strv_t strv(const char *s); +char strv_next(strv_t *s); int strv_split(strv_t *src, int chr, strv_t *dest); /* strings */ |