fix Issue 8908 - Collapse of std.csv by the specifications change of std.conv.parse

This commit is contained in:
k-hara 2012-12-11 11:12:11 +09:00
parent baf5737beb
commit b66012ef4e
2 changed files with 41 additions and 3 deletions

View file

@ -2746,7 +2746,7 @@ unittest
}
//Used internally by parse Array/AA, to remove ascii whites
private void skipWS(R)(ref R r)
package void skipWS(R)(ref R r)
{
static if (isSomeString!R)
{

View file

@ -1027,6 +1027,7 @@ public:
{
if(indices[ti] == colIndex)
{
static if (!isSomeString!ToType) skipWS(colData);
recordContent.tupleof[ti] = to!ToType(colData);
}
}
@ -1036,7 +1037,10 @@ public:
foreach(ti, ToType; FieldTypeTuple!(Contents))
{
if(ti == colIndex)
{
static if (!isSomeString!ToType) skipWS(colData);
recordContent.tupleof[ti] = to!ToType(colData);
}
}
}
recordRange.popFront();
@ -1258,7 +1262,9 @@ public:
if(skipNum)
prime(skipNum);
try curContentsoken = to!Contents(_front.data);
auto data = _front.data;
static if (!isSomeString!Contents) skipWS(data);
try curContentsoken = to!Contents(data);
catch(ConvException e)
{
throw new CSVException(e.msg, _input.row, _input.col, e);
@ -1549,7 +1555,6 @@ unittest
assert(a.data == " two \"quoted\" end");
}
// Test modifying token delimiter
unittest
{
@ -1577,3 +1582,36 @@ unittest
csvNextToken(str,a, '|','/');
assert(a.data == ""d);
}
// Bugzilla 8908
unittest
{
string csv = ` 1.0, 2.0, 3.0
4.0, 5.0, 6.0`;
static struct Data { real a, b, c; }
size_t i = 0;
foreach (data; csvReader!Data(csv)) with (data)
{
int[] row = [cast(int)a, cast(int)b, cast(int)c];
if (i == 0)
assert(row == [1, 2, 3]);
else
assert(row == [4, 5, 6]);
++i;
}
i = 0;
foreach (data; csvReader!real(csv))
{
auto a = data.front; data.popFront();
auto b = data.front; data.popFront();
auto c = data.front;
int[] row = [cast(int)a, cast(int)b, cast(int)c];
if (i == 0)
assert(row == [1, 2, 3]);
else
assert(row == [4, 5, 6]);
++i;
}
}