diff options
| author | Julian Hurst <ark@mansus.space> | 2024-11-15 01:14:07 +0100 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2024-11-15 01:14:07 +0100 |
| commit | 189c3af4052d543ce816637d97fed926fefa5c47 (patch) | |
| tree | 3e04183827064e52aeb954c5495a283c9f6ff2c6 /tsv | |
| parent | e2bee01af84bc7a6bc191f931f195b3c0b5175cc (diff) | |
| download | hatask-189c3af4052d543ce816637d97fed926fefa5c47.tar.gz | |
csv -> tsv
Diffstat (limited to 'tsv')
| -rw-r--r-- | tsv/tsv.ha | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tsv/tsv.ha b/tsv/tsv.ha new file mode 100644 index 0000000..85015a1 --- /dev/null +++ b/tsv/tsv.ha @@ -0,0 +1,22 @@ +use io; +use strings; +use fmt; + +export type error = !(str | io::error); + +export fn writerecord(w: io::handle, record: []str) (void | error) = { + let sep = ""; + for (const field .. record) { + const pfield = strings::replace(field, "\t", ""); + defer free(pfield); + fmt::fprintf(w, "{}{}", sep, pfield)!; + sep = "\t"; + }; + fmt::fprintln(w)!; +}; + +export fn writerecords(w: io::handle, records: [][]str) (void | error) = { + for (const record .. records) { + writerecord(w, record)?; + }; +}; |
