aboutsummaryrefslogtreecommitdiff
path: root/src/tsv.c
diff options
context:
space:
mode:
authorPreston Pan <ret2pop@gmail.com>2024-12-26 21:18:05 -0800
committerPreston Pan <ret2pop@gmail.com>2024-12-26 21:18:05 -0800
commitfd14f6fbf8206589d2a0ad8f0793845cb8faf1d7 (patch)
treeac3f8288b9e5e9d5e3acaf7d07694dc04157233a /src/tsv.c
parente75d6f6b8f4512a5bbfecbfa8c17f0bb687e3d55 (diff)
stuff
Diffstat (limited to 'src/tsv.c')
-rw-r--r--src/tsv.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/tsv.c b/src/tsv.c
new file mode 100644
index 0000000..9b1c2be
--- /dev/null
+++ b/src/tsv.c
@@ -0,0 +1,32 @@
+#include <stdlib.h>
+#include <stdbool.h>
+
+#include <tsv.h>
+#include <helpers.h>
+#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;
+}