csvReader read file byLine()?

Jens Mueller jens.k.mueller at gmx.de
Fri Jun 22 01:12:42 PDT 2012


Jesse Phillips wrote:
> On Thursday, 21 June 2012 at 20:30:07 UTC, Jens Mueller wrote:
> 
> >>>auto file = File(filename, "r");
> >>>auto records = csvReader!(Record)(file.byLine());
> >>>
> >>>Am I missing something? Was this left out for a reason or an
> >>>oversight?
> >>>
> >>>Jens
> >>
> >>You might make use of std.algorithm.joiner.
> >
> >The problem is that csvParser expects a range with elements of
> >type
> >dchar. Any idea why that is required for CSV parsing?
> >
> >Jens
> 
> It requires a dchar range so that Unicode support is enforced. It is
> the same reason char[] is a range of dchar.
> 
> You'll have to give me some example code, my test has no issue using
> joiner with byLine.
> 
> import std.stdio;
> import std.algorithm;
> import std.csv;
> 
> void main()
> {
>     struct Record {
>         string one, two, three;
>     }
>     auto filename = "file.csv";
>     auto file = File(filename, "r");
>     auto records = csvReader!Record(file.byLine().joiner("\n"));
>     foreach(r; records)
>     {
>         writeln(r);
>     }
> }

auto file = File("test.csv", "r");
auto records = csvReader!double(file.byLine().joiner("\n"));
writeln(records);

The last line throws a CSVException due to some conversion error
'Floating point conversion error for input "".' for the attached input.

If you change the input to
3.0
4.0
you get no exception but wrong a output of
[[4], [4]]
.

Using readText or
auto records = csvReader!Record(["3.00", "4.0"].joiner("\n"));
works as expected.

Can you reproduce the issue? I'm running dmd2.059 on Linux.
Thanks.

Jens
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.csv
Type: text/csv
Size: 8 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120622/22567b73/attachment.csv>


More information about the Digitalmars-d mailing list