core/encoding/csv

encoding_csv

Types

5

Reader

Reader :: struct { // comma is the field delimiter // reader_init will set it to be ',' // A "comma" must be a valid rune, nor can it be \r, \n, or the Unicode replacement character (0xfffd) comma: rune, // comment, if not 0, is the comment character // Lines beginning with the comment character without a preceding whitespace are ignored comment: rune, // fields_per_record is the number of expected fields per record // if fields_per_record is >0, 'read' requires each record to have that field count // if fields_per_record is 0, 'read' sets it to the field count in the first record // if fields_per_record is <0, no check is made and records may have a variable field count fields_per_record: int, // If trim_leading_space is true, leading whitespace in a field is ignored // This is done even if the field delimiter (comma), is whitespace trim_leading_space: bool, // If lazy_quotes is true, a quote may appear in an unquoted field and a non-doubled quote may appear in a quoted field lazy_quotes: bool, // multiline_fields, when set to true, will treat a field starting with a " as a multiline string // therefore, instead of reading until the next \n, it'll read until the next " multiline_fields: bool, // reuse_record controls whether calls to 'read' may return a slice using the backing buffer // for performance // By default, each call to 'read' returns a newly allocated slice reuse_record: bool, // reuse_record_buffer controls whether calls to 'read' clone the strings of each field or uses // the data stored in record buffer for performance // By default, each call to 'read' clones the strings of each field reuse_record_buffer: bool, // internal buffers r: bufio.Reader, line_count: int, raw_buffer: [dynamic]u8, record_buffer: [dynamic]u8, field_indices: [dynamic]int, last_record: [dynamic]string, sr: strings.Reader, // Set and used by the iterator. Query using `iterator_last_error` last_iterator_error: Error, }Source

Reader is a data structure used for reading records from a CSV-encoded file

The associated procedures for Reader expects its input to conform to RFC 4180.

Writer

Writer :: struct { // Field delimiter (set to ',' with writer_init) comma: rune, // if set to true, \r\n will be used as the line terminator use_crlf: bool, w: io.Writer, }Source

Writer is a data structure used for writing records using a CSV-encoding.

Constants

1

Variables

1

Procedures

14

iterator_next

iterator_next :: proc(r: ^Reader) -> (record: []string, idx: int, err: Error, more: bool)Source

Returns a record at a time.

for record, row_idx in csv.iterator_next(&r) { ... }

	TIP: If you process the results within the loop and don't need to own the results,
	you can set the Reader's `reuse_record` and `reuse_record_buffer` to true;
	you won't need to delete the record or its fields.

read

read :: proc(r: ^Reader, allocator: mem.Allocator = context.allocator) -> (record: []string, err: Error)Source

read reads a single record (a slice of fields) from r

All \r\n sequences are normalized to \n, including multi-line field

read_all

read_all :: proc(r: ^Reader, allocator: mem.Allocator = context.allocator) -> ([][]string, Error)Source

read_all reads all the remaining records from r. Each record is a slice of fields. read_all is defined to read until an EOF, and does not treat EOF as an error

write

write :: proc(w: ^Writer, record: []string) -> (io.Error)Source

write writes a single CSV records to w with any of the necessarily quoting. A record is a slice of strings, where each string is a single field.

If the underlying io.Writer requires flushing, make sure to call io.flush

Reference search

Find anything

Documentation preferences

Settings

System theme variants

Used only while Theme is set to System.