#encoding/csv
Xu 0.16.0 API
import: #encoding/csv
counts: 3 functions, 13 methods, 2 types, 0 constants, 0 method sets
RFC4180 Reader/Writer over owning strings.
struct Reader
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
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
pub fn new_reader(data string) Reader
Purpose
Construct reader.
Parameters
data string- data (string)
Returns
Reader — a value of this type
new_writer
pub fn new_writer() Writer
Purpose
Construct writer.
Parameters
No arguments are required.
Returns
Writer — a value of this type
host_crlf
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
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.
($&Writer) set_comma
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
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
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
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
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
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
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
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
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
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
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.