diff options
author | Preston Pan <ret2pop@gmail.com> | 2025-01-30 21:02:42 -0800 |
---|---|---|
committer | Preston Pan <ret2pop@gmail.com> | 2025-01-30 21:02:42 -0800 |
commit | 3780f207f924f14734cb839fd015bd883fe52ff1 (patch) | |
tree | de13568dbf97ffe477943854bcb3ea6001b46cf8 /src/common/bsv.c | |
parent | ef9ab1fd141f4057d41f2d6ed8ab8d67c44894d5 (diff) |
Diffstat (limited to 'src/common/bsv.c')
-rw-r--r-- | src/common/bsv.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common/bsv.c b/src/common/bsv.c new file mode 100644 index 0000000..4a3d000 --- /dev/null +++ b/src/common/bsv.c @@ -0,0 +1,33 @@ +#include <stdlib.h> +#include <stdbool.h> + +#include "../include/tsv.h" +#include "../include/helpers.h" +#include "../include/better_string.h" + +tsv_t *init_tsv(char *source, char delim) { + tsv_t *tsv = safe_calloc(1, sizeof(tsv_t *)); + tsv->source = source; + tsv->i = 0; + tsv->c = tsv->source[tsv->i]; + tsv->delim = delim; + return tsv; +} + +void tsv_move(tsv_t *tsv) { + if (tsv->c != '\0') { + tsv->i++; + tsv->c = tsv->source[tsv->i]; + } +} + +string_t *tsv_next(tsv_t *tsv) { + string_t *s = init_string(NULL); + bool escape = false; + while (tsv->c != tsv->delim && !escape) { + if (tsv->c == '\0') break; + string_push(s, tsv->c); + tsv_move(tsv); + } + return s; +} |