diff options
Diffstat (limited to 'tsv/tsv.ha')
| -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)?; + }; +}; |
