mirror of https://github.com/adamdruppe/arsd.git
wow i write awful, useless, untested code
This commit is contained in:
parent
fdd8eec60e
commit
e9b1f5c650
12
csv.d
12
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue