csv :: CsvDocument
csv :: CsvDocument :: add_record
Adds a new record to document containing the values inobjs
csv :: CsvDocument :: defaultinit
csv $ CsvDocument :: SELF
Type of this instance, automatically specialized in every classcsv :: CsvStream :: _delimiter
The character that delimits escaped value.csv :: CsvStream :: _separator
The character that split each cell in a record.csv :: CsvDocument :: add_record
Adds a new record to document containing the values inobjs
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
csv :: CsvStream :: defaultinit
core :: Writable :: defaultinit
csv :: CsvDocument :: defaultinit
core :: Object :: defaultinit
csv :: CsvStream :: delimiter=
The character that delimits escaped value.core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).csv :: CsvStream :: separator=
The character that split each cell in a record.core :: Writable :: write_to_bytes
Likewrite_to
but return a new Bytes (may be quite large)
core :: Writable :: write_to_file
Likewrite_to
but take care of creating the file
core :: Writable :: write_to_string
Likewrite_to
but return a new String (may be quite large).
# A CSV document representation.
class CsvDocument
super Writable
super CsvStream
# The header.
#
# Contains the name of all fields in this table.
var header = new Array[String] is writable, optional
# The list of the records.
#
# All records must have the same length than `header`.
var records = new Array[Array[String]] is writable, optional
# Adds a new record to document containing the values in `objs`
fun add_record(objs: Object...) do
var ln = new Array[String].with_capacity(objs.length)
for i in objs do ln.add(i.to_s)
records.add ln
end
redef fun write_to(stream) do
var s = new CsvWriter(stream)
s.separator = separator
s.eol = eol
s.delimiter = delimiter
if not header.is_empty then
s.write_line header
end
s.write_lines(records)
end
# Load from the specified stream.
#
# Parameters:
#
# * `stream`: Input stream.
# * `has_header`: Is the first record the header? - defaults to true
# * `skip_empty`: Do we skip the empty lines? - defaults to true
fun load_from(stream: Reader, has_header: nullable Bool, skip_empty: nullable Bool) do
if has_header == null then has_header = true
if skip_empty == null then skip_empty = true
var reader = new CsvReader(stream)
reader.separator = separator
reader.eol = eol
reader.delimiter = delimiter
reader.skip_empty = skip_empty
end
end
lib/csv/csv.nit:116,1--165,3