From e9b1f5c650971003bd53d58399904b0dbad84692 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Tue, 29 Jan 2019 14:21:18 -0500 Subject: [PATCH] wow i write awful, useless, untested code --- csv.d | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/csv.d b/csv.d index 72fe093..c770952 100644 --- a/csv.d +++ b/csv.d @@ -6,9 +6,10 @@ import std.array; /// string[][] readCsv(string data) { + data = data.replace("\r\n", "\n"); data = data.replace("\r", ""); - auto idx = data.indexOf("\n"); + //auto idx = data.indexOf("\n"); //data = data[idx + 1 .. $]; // skip headers string[] fields; @@ -39,9 +40,9 @@ string[][] readCsv(string data) { field ~= c; break; case 1: // in quote - if(c == '"') + if(c == '"') { state = 2; - else + } else field ~= c; break; case 2: // is it a closing quote or an escaped one? @@ -55,6 +56,11 @@ string[][] readCsv(string data) { } } + if(field !is null) + current ~= field; + if(current !is null) + records ~= current; + return records; }