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) {
|
string[][] readCsv(string data) {
|
||||||
|
data = data.replace("\r\n", "\n");
|
||||||
data = data.replace("\r", "");
|
data = data.replace("\r", "");
|
||||||
|
|
||||||
auto idx = data.indexOf("\n");
|
//auto idx = data.indexOf("\n");
|
||||||
//data = data[idx + 1 .. $]; // skip headers
|
//data = data[idx + 1 .. $]; // skip headers
|
||||||
|
|
||||||
string[] fields;
|
string[] fields;
|
||||||
|
|
@ -39,9 +40,9 @@ string[][] readCsv(string data) {
|
||||||
field ~= c;
|
field ~= c;
|
||||||
break;
|
break;
|
||||||
case 1: // in quote
|
case 1: // in quote
|
||||||
if(c == '"')
|
if(c == '"') {
|
||||||
state = 2;
|
state = 2;
|
||||||
else
|
} else
|
||||||
field ~= c;
|
field ~= c;
|
||||||
break;
|
break;
|
||||||
case 2: // is it a closing quote or an escaped one?
|
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;
|
return records;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue