- # Do not close the input stream.
- redef fun finish do row = null
-
- # Close the input stream.
- fun close do istream.close
-
- private fun read_row: nullable Array[String] do
- if istream.eof then return null
- var row = new Array[String]
- var value = new RopeBuffer
-
- # Number of unescaped characters since the last delimiter or separator.
- var unescaped = 0
-
- # Do we read the start of a row?
- var got_row = false
-
- # Do we found a delimited string in the current cell?
- var got_delimiter = false
-
- loop
- var c = istream.read_char
-
- if c == null then
- if got_row then
- row.add value.to_s
- return row
- else
- return null
- end
- end
-
- if c == format.delimiter then
- if got_delimiter and unescaped == 0 then
- # Got an escaped delimiter.
- value.add format.delimiter
- end
- # Read all bytes until the delimiter.
- loop
- c = istream.read_char
- assert not_eof: c != null else
- sys.stderr.write "Unexpected end of file before the end of a delimited value.\n"
+ # Optional parameter `has_header` determines whether the first line
+ # of the CSV Document is header data.
+ # Defaults to true
+ fun read_all(has_header: nullable Bool): CsvDocument do
+ var header: nullable Array[String] = null
+ if has_header == null then has_header = true
+ var iss = istream
+ var res_data = new Array[Array[String]]
+ var eol_st = eol.first
+ var line = new Array[String]
+ var esc = delimiter
+ var sep = separator
+ var eol = eol
+ var is_eol = false
+ var eol_buf = new Buffer.with_cap(eol.length)
+ var c = iss.read_char
+ var el = new Buffer
+ while not iss.eof do
+ if c == null then continue
+ loop
+ if c == esc then
+ c = iss.read_char
+ loop
+ if c == esc then
+ c = iss.read_char
+ if c != esc then break
+ end
+ if c == null then break
+ el.add c
+ c = iss.read_char