Axle v0.14.1
Package

std/text/csv

std/csv — RFC 4180 single-row parser, in pure Axle.

Index-based access (no array return):

let n : i32 = csvFieldCount(line);
for (let i : i32 = 0; i < n; i = i + 1) {
println(csvField(line, i));
}

Quoting rules: a field starting with " ends at the next " not
followed by another ". Inside a quoted field, "" represents a
literal ". Whitespace around commas is preserved (no auto-trim).

Multi-line records (a " straddling a newline) are NOT supported —
feed each row separately via string.split("\n").

Field extraction reads the row byte-by-byte and rebuilds each field
by widening every content byte to its U+00xx scalar (so a byte
≥ 128 becomes its two-byte UTF-8 form), matching the row parser's
established byte→char handling. csvEncode instead copies bytes
verbatim, so valid UTF-8 fields round-trip unchanged.

Free functions

TypeMethod and description
i32
csvFieldCount(line : string) : i32 Number of fields in a single CSV row (quoting-aware), so a caller
can loop over them without materialising an array.
string
csvField(line : string, index : i32) : string The index-th field of a single CSV row, with quoting unwound.
Raises IndexOutOfBoundsException when index is outside
[0, csvFieldCount(line)).
string
csvEncode(field : string) : string Encode a single field — wraps in " and escapes inner " as ""
whenever the field contains ,, ", or \n. Bytes are copied
verbatim, so a valid-UTF-8 field round-trips unchanged. Pass the
result through csvJoin* to build a row.
string
csvJoin2(a : string, b : string) : string Join two already-encoded fields with a , separator. Wider rows are
built by composition (csvJoin2(csvJoin2(a, b), c)) or plain +
concatenation — there is no fixed-arity csvJoin3 / csvJoin4, the
arity cutoff was arbitrary.

Method detail

#csvFieldCount

csvFieldCount(line : string) : i32

Number of fields in a single CSV row (quoting-aware), so a caller
can loop over them without materialising an array.

Parameters
line one RFC 4180 CSV row to count the fields of

#csvField

csvField(line : string, index : i32) : string ! IndexOutOfBoundsException

The index-th field of a single CSV row, with quoting unwound.
Raises IndexOutOfBoundsException when index is outside
[0, csvFieldCount(line)).

Parameters
line the RFC 4180 CSV row to extract from
index zero-based field position within the row

#csvEncode

csvEncode(field : string) : string

Encode a single field — wraps in " and escapes inner " as ""
whenever the field contains ,, ", or \n. Bytes are copied
verbatim, so a valid-UTF-8 field round-trips unchanged. Pass the
result through csvJoin* to build a row.

Parameters
field raw field value to quote/escape per RFC 4180

#csvJoin2

csvJoin2(a : string, b : string) : string

Join two already-encoded fields with a , separator. Wider rows are
built by composition (csvJoin2(csvJoin2(a, b), c)) or plain +
concatenation — there is no fixed-arity csvJoin3 / csvJoin4, the
arity cutoff was arbitrary.

Parameters
a first already-encoded field (left of the comma)
b second already-encoded field (right of the comma)