Skip to content

std.csv

rfc 4180 reader; sep ‘,’ ‘;’ or tab; LF/CRLF; skips empty lines and a bom fields are slices of the text; only a quoted field with “” is copied into the arena

pub CsvError :: errors {
unterminated_quote,
}
  • unterminated_quote: a field in quotes runs to the end of the text
pub CsvReader :: struct {
text: []const u8,
at: usize,
sep: u8,
line: usize,
breaks: usize,
}

not Reader: would clash with std.io’s (modules share one type namespace)

  • at: where the next record starts
  • line: the line the last record started on, from 1
  • breaks: the line breaks read so far
pub done :: fn(self: *Self) -> bool

true once every record is read

pub next :: fn(self: *Self, a: *Arena) -> [][]const u8 ! CsvError

next record’s fields, in a; empty when done

pub reader :: fn(text: []const u8, sep: u8) -> CsvReader

reader over text; sep 44 ‘,’, 59 ‘;’, 9 tab

pub records :: fn(text: []const u8, sep: u8, a: *Arena) -> [][][]const u8 ! CsvError

all records, fields in a

pub guess_separator :: fn(text: []const u8) -> u8

most common of ‘;’ tab ‘,’ on line 1, outside quotes; ‘,’ if none