#include #include #include "../include/bsv.h" #include "../include/helpers.h" #include "../include/better_string.h" bsv_t *init_bsv(char *source, char delim) { bsv_t *bsv = safe_calloc(1, sizeof(bsv_t *)); bsv->source = source; bsv->i = 0; bsv->c = bsv->source[bsv->i]; bsv->delim = delim; return bsv; } void bsv_move(bsv_t *bsv) { if (bsv->c != '\0') { bsv->i++; bsv->c = bsv->source[bsv->i]; } } string_t *bsv_next(bsv_t *bsv) { string_t *s = init_string(NULL); bool escape = false; while (bsv->c != bsv->delim && !escape) { if (bsv->c == '\0') break; string_push(s, bsv->c); bsv_move(bsv); } return s; }