Skip to main content

Module dialect

Module dialect 

Source
Expand description

The delimited-file DIALECT layer – what makes kobold-csv CSV-aware.

A Dialect fixes the four parameters that decide how a flat record of string fields becomes one line of delimited text and back: the field delimiter (, | \t …), the quote character, whether to quote quote_all fields unconditionally, and the LineTerminator used between rows.

§Quoting (RFC-4180 style)

A field is QUOTED when it contains the delimiter, the quote character, a carriage return, or a line feed (or always, when quote_all). Inside a quoted field an embedded quote is DOUBLED (" -> ""). This is the de-facto CSV escaping convention (RFC 4180, and what spreadsheets/COPY ... CSV agree on). Doing it by hand – rather than depending on a CSV crate – keeps kobold-csv std-only and lets the escaping itself be evidence (KOBOLD.CSV.ESCAPE): the writer and the fail-closed reader are exact inverses.

§Fail-closed reader

parse_row is deliberately strict: a quote that opens a field but never closes, or stray text after a closing quote, is a Finding, NEVER a best-effort guess. A reconciliation tool must be able to trust that a row either parsed exactly or was rejected with a reason – silent recovery would corrupt custody.

This module is independent of GnuCOBOL/libcob.

Structs§

Dialect
A delimited-file dialect: delimiter, quote char, quote-all flag, and line terminator.

Enums§

LineTerminator
The line terminator a dialect writes between rows (and tolerates when reading).

Functions§

parse_row
KOBOLD.CSV.ESCAPE / parse evidence: FAIL-CLOSED parse of one line of delimited bytes into its fields under dialect d.
write_field
Write one field to out under dialect d, quoting and doubling embedded quotes as required. The inverse of parse_row’s field handling: write_field/parse_row are an exact round-trip pair.
write_row
Write a full row of fields to out under dialect d, joining with the delimiter and appending the line terminator. Does NOT add a trailing terminator beyond this row’s own.