Skip to main content

Module delimited

Module delimited 

Source
Expand description

Delimited text (CSV, and the tab-separated text a spreadsheet puts on the clipboard): ONE reader, so a spreadsheet export pasted into the CAD app and the same file imported into the PLM read the same cells.

The grammar is RFC 4180’s, read generously where that costs nothing:

  • a record ends at \n, \r\n or a lone \r; a trailing line break does not make an empty last record;
  • a field is quoted when its first character other than spaces is " (the spaces are dropped); inside quotes "" is a quote, and separators and line breaks are text;
  • a " anywhere else in an unquoted field is an ordinary character (5" bolt);
  • a blank line is a record of one empty field. Callers that skip blank lines test Record::is_blank.

Strictness decides only what malformed quoting does. A Strictness::Lenient read (a paste: show what the user copied, never refuse it) closes an unterminated quote at the end of the text and keeps text after a closing quote; a Strictness::Strict read (an import that writes data) refuses both, naming the line.

A byte-order mark is not part of the grammar: strip_bom removes one, and every caller that reads a file or a spreadsheet’s clipboard calls it.

Structs§

Record
One record, with the 1-based line it starts on.

Enums§

Strictness
What malformed quoting does (see the module documentation).

Functions§

parse
The records of text, fields split on separator. A Strictness::Lenient read never returns Err.
sniff_separator
The separator a CSV-or-TSV text uses: a tab when its first non-blank line holds a tab and no comma (a paste from a spreadsheet), else a comma.
strip_bom
text without a leading UTF-8 byte-order mark.