[Issue 23383] csvReader throws ArrayIndexError when Contents has more fields than header.length
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 5 04:01:35 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23383
Jesse Phillips <Jesse.K.Phillips+D at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |Jesse.K.Phillips+D at gmail.co
| |m
--- Comment #1 from Jesse Phillips <Jesse.K.Phillips+D at gmail.com> ---
I think you're probably right, but what about
class Layout
{
int value;
double other;
string name;
}
struct Cache {
Layout data;
alias data this;
int extra_field; // un-comment to see the error
static Cache opCall(Layout d) {
Cache c;
c.data = d;
return c;
}
}
void main()
{
import std.csv;
import std.stdio: write, writeln, writef, writefln;
import std.algorithm.comparison : equal;
import std.algorithm : map;
string text = "a,b,c\nHello,65,2.5\nWorld,123,7.5";
auto records =
text.csvReader!Layout(["b","c","a"])
.map!(x => Cache(x)) ; // Read only these column
foreach (r; records) writeln(r.name);
}
--
More information about the Digitalmars-d-bugs
mailing list