codec/csv
lib/codec/csv.vklib/codec/csv.vk Pure-Veko RFC 4180 CSV parser, header-mapped record decoder, and serializer. Zero capabilities required.
parse = fn [input str] block[block[str]]
Parses RFC 4180 CSV text into rows of string fields (block[block[str]]).
Supports quoted fields, embedded commas/newlines, and "" escaped quotes.
Executable Example
use [csv = codec/csv]
rows = csv/parse 'name,note\nalpha,"hello, ""world"""\nbeta,plain'
if (len rows) != 3 or rows[1][1] != 'hello, "world"' [ err 'csv/parse' ] else [ .ok ]
parse-records = fn [input str] block[map[str]]
Parses CSV text whose first row contains column headers into block[map[str]].
Executable Example
use [csv = codec/csv]
recs = csv/parse-records 'host,port\napi.local,8443\ndb.local,5432'
if (len recs) != 2 or (map/get recs[0] 'port') != '8443' [ err 'csv records' ] else [ .ok ]
encode = fn [rows block[block[str]]] str
Encodes rows (block[block[str]]) into RFC 4180 CSV text separated by \n.