On Fri, 28 Oct 2011 19:41:35 +0300, Jesse Phillips
<jessekphillip...@gmail.com> wrote:
Vladimir Panteleev Wrote:
On Fri, 28 Oct 2011 16:18:27 +0300, dsimcha <dsim...@yahoo.com> wrote:
> Docs:
> http://nascent.freeshell.org/programming/D/doc/phobos/std_csv.html
Documentation should have examples of basic usage at the top. It should
be
possible to figure out how to use a CSV parser within 10 seconds of
looking at the docs.
Sounds good. What kind of example should be first? Maybe something that
just gives you an itterable:
auto records = csvText(text);
That's not a very good example, since it doesn't show anything about how
to use the result of the csvText call. If it's an iterable, the example
should use it in a foreach loop.
IMO the example should be a very simple realistic use case, for example
printing the data in a user-friendly way:
writefln("%s works as a %s and earns %d per year", ...);
It looks like this is only a CSV parser, but not a CSV formatter? That's
pretty weird. It'd be like std.xml or std.json only having reading
functionality.
I have done quite a bit of CSV output and none of them have been the
same. The only similarity is surrounding with quotes and escaping quotes.
"\"" ~ text.replace("\"", "\"\"") ~ "\""
The problem is that how your data is stored and where it needs to go is
different for each app. I don't see a reason to provide a output
function where one must convert their data into a range of struct and
specify an output range, when that conversion is the hard part.
I would consider a function that does escaping/quoting only if the
element needs it. But such a function couldn't work on an Input Range.
I think you're overcomplicating this.
You already have a way of specifying the specific format of the CSV file
(delimiters, quote characters) for the parser. Use the same idiom for the
formatter.
The formatter should accept data in the same format (datatypes) as what's
emitted by the parser. If you use functional idioms (ranges), it ought to
be possible to pipe it all together neatly.
The specifics don't matter very much, but it should be possible to put
some data (array of string arrays, array of structs or whatnot) into a
.csv file in a single line of code. Surely this isn't hard?
--
Best regards,
Vladimir mailto:vladi...@thecybershadow.net