diff options
author | Preston Pan <ret2pop@gmail.com> | 2024-12-28 16:47:43 -0800 |
---|---|---|
committer | Preston Pan <ret2pop@gmail.com> | 2024-12-28 16:47:43 -0800 |
commit | 1fd608288ee47c2c560817f12f14b21069fed2f6 (patch) | |
tree | e6460b92dba5bb0d089c8c2a4e794e3504098359 /src/common/tsv.c | |
parent | 63f11aaec8d21844a07fd27003a992c102a3a297 (diff) |
makefile and directory structure change completely to build client and server
Diffstat (limited to 'src/common/tsv.c')
-rw-r--r-- | src/common/tsv.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/common/tsv.c b/src/common/tsv.c new file mode 100644 index 0000000..c06163b --- /dev/null +++ b/src/common/tsv.c @@ -0,0 +1,32 @@ +#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) { + tsv_t *tsv = safe_calloc(1, sizeof(tsv_t *)); + tsv->source = source; + tsv->i = 0; + tsv->c = tsv->source[tsv->i]; + 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 != '\t' && !escape) { + if (tsv->c == '\0') break; + string_push(s, tsv->c); + tsv_move(tsv); + } + return s; +} |