On 13/10/2017 11:05 AM, Dmitry wrote:
On Friday, 13 October 2017 at 09:00:52 UTC, rikki cattermole wrote:
Write a purpose built csv parser using ranges. It should take only
about half an hour.
I know, I know not very helpful. But a custom built parser will work
better for you I think.
Yep, I can parse it myself, but I want to try to avoid this (reduce
amount of source code).
Maybe there is posiible something like this:
foreach(record; file.byLine.fixQuotes.joiner("\n").csvReader!...
?
What types should get/return the function (fixQuotes) if I want change
the line after .byLine?
When compiler says:
"candidates are:
src\phobos\std\array.d(2534,5): std.array.replaceFirst(E, R1, R2)(E[]
subject, R1 from, R2 to) if (isDynamicArray!(E[]) && isForwardRange!R1
&& is(typeof(appender!(E[])().put(from[0..1]))) && isForwardRange!R2 &&
is(typeof(appender!(E[])().put(to[0..1]))))"
it's scares me and I hiding under the table.
I thought about something like
auto fixQuotes(string text)
{
if (text.canFind("\"\""))
{
// some magic
}
return text;
}
but obviously, it won't compiled
Something along the lines of:
.byLine.map!(a => a.fixQuotes).joiner("\n").csvReader!...
Either way, you're using ranges!
Its even the same amount of code, if not less.