diff options
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/parse.c b/parse.c new file mode 100644 index 0000000..a1a68d8 --- /dev/null +++ b/parse.c @@ -0,0 +1,23 @@ +#include "parse.h" + +int parse_doc(enum doc_type type, struct doc *d, const buf_t *b) { + switch (type) { + case DOC_PLAIN: + doc_init(d); + for (size_t i = 0; i < b->sz; i++) { + char c = b->buf[i]; + if (c == '\n') { + doc_new_line(d); + } else { + doc_add_textn(d, &c, 1); + } + } + goto ok; + default: + goto err; + } +ok: + return 0; +err: + return -1; +} |