diff --git a/std/conv.d b/std/conv.d index e4ed3f6ec..d3434ebe4 100644 --- a/std/conv.d +++ b/std/conv.d @@ -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) { diff --git a/std/csv.d b/std/csv.d index 3ad2ec4b7..fedf41042 100644 --- a/std/csv.d +++ b/std/csv.d @@ -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; + } +}