blob: a1a68d823145926e8c8c9186e677f042f6f5b202 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
}
|