6.22.13 CSV Reader

Comma-separated values (CSV) are a popular text format to interchange data. Gforth provides words for reading CSV files (with all features, including newlines in quoted strings).

read-csv ( addr u xt –  ) gforth-experimental “read-csv”

Read CVS file addr u and execute xt for every field found. Xt has the stack effect ( addr u field line -- ), i.e. the field string (in de-quoted form), the current field number (starting with 0), and the current line (starting with 1).

csv-separator ( – c  ) gforth-experimental “csv-separator”

CSV field separator (default is ‘,’, hence the name "comma-separated"); this is a value and can be changed with to csv-separator.

csv-quote ( – c  ) gforth-experimental “csv-quote”

CSV quote character (default is ‘"’); this is a value and can be changed with to csv-quote.

.quoted-csv ( c-addr u –  ) gforth-experimental “dot-quoted-csv”

print a field in CSV format, i.e., with enough quotes that read-csv will produce c-addr u when encountering the output of .quoted-csv.