Skip to content

std.csv - ZZ

RFC4180 subset: quoted fields, "" escapes, embedded newlines, CRLF. Rows are [[str]] (first row = header when present). Unterminated trailing quotes are treated as end-of-field.

import std.csv

std.csv parses and stringifies CSV. csv.parse(src) uses ,; csv.parse_delim(src, d) uses a custom one-char delimiter. Round-trips via stringify/stringify_delim. Header-keyed JSON via to_json. Suitable for config, data import/export, and simple spreadsheets.

import std.csv
rows := csv.parse("a,b\n1,2\n")
csv.header(rows) // ["a", "b"]
csv.get_cell(rows, 1, 0, "?") // "1"
csv.stringify(rows) // round-trips: "a,b\n1,2\n"
csv.to_json(rows) // JSON array of objects

14 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.

Function Signature Description
std.csv.delim_first delim_first(delimiter: str) -> str Detect/normalize first delimiter
std.csv.escape_cell escape_cell(cell: str) -> str Escape a single cell
std.csv.get_cell get_cell(rows: [[str]], r: int, c: int, default: str) -> str Bounds-checked cell
std.csv.header header(rows: [[str]]) -> [str] First row ([] when empty)
std.csv.json_escape json_escape(s: str) -> str Escape a string for JSON embedding
std.csv.len len(rows: [[str]]) -> int Row count
std.csv.needs_quote needs_quote(cell: str, d: str) -> bool Cell needs quoting under delimiter
std.csv.parse parse(src: str) -> [[str]] Parse with , delimiter
std.csv.parse_delim parse_delim(src: str, delimiter: str) -> [[str]] Parse with custom delimiter
std.csv.records records(rows: [[str]]) -> [[str]] All rows after the first
std.csv.stringify stringify(rows: [[str]]) -> str Serialize with , (quotes when needed)
std.csv.stringify_delim stringify_delim(rows: [[str]], delimiter: str) -> str Serialize with custom delimiter
std.csv.to_json to_json(rows: [[str]]) -> json Header-keyed JSON array
std.csv.validate validate(src: str) -> bool Non-empty parse
  • std.json — Parse, stringify and read individual values out of JSON.
  • std.map — Pure dictionary helpers over plain maps: lookup, merge and keys.
  • std.set — Arrays with uniqueness: membership, union, intersection and difference.
  • std.dec — Exact decimal arithmetic carried as strings, so money never becomes a float.
  • std.property — Seeded generators and shrinking for property-based tests.

Full index: API reference · Standard library