XU XUv0.16.0

#encoding/csv

import: #encoding/csv

counts: 3 functions, 13 methods, 2 types, 0 constants, 0 method sets

RFC4180 Reader/Writer over owning strings.

struct Reader

XuAPI
pub struct Reader {
    pub data string
    pub pos int
    pub comma int
    pub comment int
    pub lazy_quotes bool
    pub sticky string
    pub fields_per_record int
    pub trim_leading_space bool
    pub learned int
}

Purpose

Csv Streaming reader and decoder.

Public fields

data string
data
pos int
field (int)
comma int
field (int)
comment int
field (int)
lazy_quotes bool
field (bool)
sticky string
field (string)
fields_per_record int
field (int)
trim_leading_space bool
field (bool)
learned int
field (int)

struct Writer

XuAPI
pub struct Writer {
    pub buf string
    pub comma int
    pub need_nl bool
    pub use_crlf bool
}

Purpose

Csv Streaming writer and encoder.

Public fields

buf string
buffer
comma int
field (int)
need_nl bool
field (bool)
use_crlf bool
field (bool)

new_reader

XuAPI
pub fn new_reader(data string) Reader

Purpose

Construct reader.

Parameters

data string
data (string)

Returns

Reader — a value of this type

new_writer

XuAPI
pub fn new_writer() Writer

Purpose

Construct writer.

Parameters

No arguments are required.

Returns

Writer — a value of this type

host_crlf

XuAPI
pub fn host_crlf() bool

Purpose

host_crlf is true on Windows (xu_target_os==2). csv.Writer.UseCRLF defaults false on every OS; callers that want native CSV line endings can set_use_crlf(csv.host_crlf).

Parameters

No arguments are required.

Returns

bool — true or false

($&Reader) set_comma

XuAPI
pub fn (r $&Reader) set_comma(c int)

Purpose

Operation on $&Reader: set comma.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).
c int
byte or character code (int)

Returns

This call does not return a value.

($&Reader) set_comment

XuAPI
pub fn (r $&Reader) set_comment(c int)

Purpose

Operation on $&Reader: set comment.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).
c int
byte or character code (int)

Returns

This call does not return a value.

($&Writer) set_comma

XuAPI
pub fn (w $&Writer) set_comma(c int)

Purpose

Operation on $&Writer: set comma.

Parameters

w $&Writer
The Writer instance used by this call (exclusive borrow).
c int
byte or character code (int)

Returns

This call does not return a value.

($&Writer) set_use_crlf

XuAPI
pub fn (w $&Writer) set_use_crlf(on bool)

Purpose

Operation on $&Writer: set use crlf.

Parameters

w $&Writer
The Writer instance used by this call (exclusive borrow).
on bool
on (bool)

Returns

This call does not return a value.

($&Reader) set_lazy_quotes

XuAPI
pub fn (r $&Reader) set_lazy_quotes(on bool)

Purpose

Operation on $&Reader: set lazy quotes.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).
on bool
on (bool)

Returns

This call does not return a value.

($&Reader) set_trim_leading_space

XuAPI
pub fn (r $&Reader) set_trim_leading_space(on bool)

Purpose

Operation on $&Reader: set trim leading space.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).
on bool
on (bool)

Returns

This call does not return a value.

($&Reader) set_fields_per_record

XuAPI
pub fn (r $&Reader) set_fields_per_record(n int)

Purpose

Operation on $&Reader: set fields per record.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).
n int
count, length, or limit (int)

Returns

This call does not return a value.

($&Reader) read

XuAPI
pub fn (r $&Reader) read() []string

Purpose

read returns the next record, or Err('eof') when exhausted. Throws on failure; handle the error or propagate it to the caller.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).

Returns

[]string — slice result

($&Reader) read_all

XuAPI
pub fn (r $&Reader) read_all() [][]string

Purpose

Operation on $&Reader: read all. Throws on failure; handle the error or propagate it to the caller.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).

Returns

[][]string — slice result

($&Writer) write

XuAPI
pub fn (w $&Writer) write(record &[]string) int

Purpose

Operation on $&Writer: write data and return the byte count.

Parameters

w $&Writer
The Writer instance used by this call (exclusive borrow).
record &[]string
record (read-only borrow; caller keeps the original; type &[]string)

Returns

int — bytes written

($&Writer) write_all

XuAPI
pub fn (w $&Writer) write_all(records &[][]string) int

Purpose

Operation on $&Writer: write all.

Parameters

w $&Writer
The Writer instance used by this call (exclusive borrow).
records &[][]string
records (read-only borrow; caller keeps the original; type &[][]string)

Returns

int — a value of this type

(&Writer) text

XuAPI
pub fn (w &Writer) text() string

Purpose

Operation on &Writer: return the current text.

Parameters

w &Writer
The Writer instance used by this call (borrow).

Returns

string — result string

($&Writer) flush

XuAPI
pub fn (w $&Writer) flush()

Purpose

Operation on $&Writer: flush buffered data.

Parameters

w $&Writer
The Writer instance used by this call (exclusive borrow).

Returns

This call does not return a value.