Skip to content

encoding.csv #

Reader example

import encoding.csv

data := 'x,y\na,b,c\n'
mut parser := csv.new_reader(data)
// read each line
for {
    items := parser.read() or { break }
    println(items)
}

It prints:

['x', 'y']
['a', 'b', 'c']

fn decode #

fn decode[T](data string) []T

decode csv to struct

fn new_reader #

fn new_reader(data string, config ReaderConfig) &Reader

new_reader initializes a Reader with string data to parse and, optionally, a custom delimiter.

fn new_writer #

fn new_writer(config WriterConfig) &Writer

new_writer returns a reference to a Writer

fn (Reader) read #

fn (mut r Reader) read() ![]string

read reads a row from the CSV data.
If successful, the result holds an array of each column's data.

fn (Writer) write #

fn (mut w Writer) write(record []string) !bool

write writes a single record

fn (Writer) str #

fn (mut w Writer) str() string

str returns the writer contents

struct ReaderConfig #

struct ReaderConfig {
	delimiter u8 = `,`
	comment   u8 = `#`
}

struct WriterConfig #

struct WriterConfig {
	use_crlf  bool
	delimiter u8 = `,`
}