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
| Type | Method and description |
|---|---|
| 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. |
| 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)). |
| csvEncode(field : string) : string Encode a single field — wraps in " and escapes inner " as ""whenever the field contains ,, ", or \n. Bytes are copiedverbatim, so a valid-UTF-8 field round-trips unchanged. Pass the result through csvJoin* to build a row. |
| csvJoin2(a : string, b : string) : string Join two already-encoded fields with a , separator. Wider rows arebuilt by composition ( csvJoin2(csvJoin2(a, b), c)) or plain +concatenation — there is no fixed-arity csvJoin3 / csvJoin4, thearity cutoff was arbitrary. |
Method detail
#csvFieldCount
Number of fields in a single CSV row (quoting-aware), so a caller
can loop over them without materialising an array.
line one RFC 4180 CSV row to count the fields of#csvField
The index-th field of a single CSV row, with quoting unwound.
Raises IndexOutOfBoundsException when index is outside[0, csvFieldCount(line)).
line the RFC 4180 CSV row to extract fromindex zero-based field position within the row#csvEncode
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.
field raw field value to quote/escape per RFC 4180#csvJoin2
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.
a first already-encoded field (left of the comma)b second already-encoded field (right of the comma)