Merge: Simplify CSV
authorJean Privat <jean@pryen.org>
Tue, 3 May 2016 15:04:31 +0000 (11:04 -0400)
committerJean Privat <jean@pryen.org>
Tue, 3 May 2016 15:04:31 +0000 (11:04 -0400)
commit31ed46111fb865e083c06518673a1a6495d0f5b5
tree4dbabe55b7e7618c2cc0d46675e5a70a25da8b9c
parent6578e32b606a7aa6996932173acccaa5b0932c47
parentd357b77dd6ae581fb5fb22ce98585c62849c5263
Merge: Simplify CSV

This PR is a rewriting of the CSV library, it should now be easier to use and should not fail anymore due to `\r\n` being the default, this one has been replaced by a single `\n` character.

The `CSVFormat` class has been removed since it introduced more complexity than usefulness, and now the separator, eol and delimiter can be set independently after creation of the `CsvDocument` or a `CsvReader/Writer`.

Concerning performance, the new parser is way faster than the old one.
On a simple 4Mio file, parsing used to take 2.401s.
On the new parser, the measured user time is 0.179s, hence an improvement by a factor of ~12.

Old code sample
~~~nit
import csv

var fl = new FileReader.open(args[0])
var rd = new CsvReader.with_format(fl, new CsvFormat('"', ',', "\r"))

var lns = new Array[Array[String]]
for i in rd do lns.add i
~~~

New code sample
~~~nit
import csv

var rd = new CsvReader.from_string(args[0].to_path.read_all)
rd.eol = "\r"
rd.read_all
~~~

Pull-Request: #2048
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Jean Privat <jean@pryen.org>