ben-strasser / fast-cpp-csv-parser

fast-cpp-csv-parser
BSD 3-Clause "New" or "Revised" License
2.15k stars 440 forks source link

too few colomns #37

Closed skinkie closed 7 years ago

skinkie commented 7 years ago

I'm trying to parse a GTFS file, with a certain number of columns. Is this code conceptually able to parse columns in a random order as long as they are mentioned in the header? Using this code:

    io::CSVReader<3> in("/mnt/volatile/skinkie/calgary/stops.txt");
    in.read_header(io::ignore_extra_column, "stop_id", "stop_lat", "stop_lon");
    std::string quaycoderef; float latitude; double longitude;
    while(in.read_row(quaycoderef, latitude, longitude)){

I get the following error:

terminate called after throwing an instance of 'io::error::too_few_columns'
  what():  Too few columns in line 2 in file "/mnt/volatile/skinkie/calgary/stops.txt".

With the data:

stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type
112112,112112,"Crescent Heights High School",51.060931,-114.065158,,,0

I have also tried:

    io::CSVReader<3, io::trim_chars<' '>, io::double_quote_escape<',','\"'>> in("/mnt/volatile/skinkie/calgary/stops.txt");

and...

    io::CSVReader<9, io::trim_chars<' '>, io::double_quote_escape<',','\"'>> in("/mnt/volatile/skinkie/calgary/stops.txt");

    in.read_header(io::ignore_extra_column, "stop_id", "stop_code", "stop_name", "stop_desc", "stop_lat", "stop_lon", "zone_id", "stop_url", "location_type");
    std::string quaycoderef; std::string stop_code; std::string stop_name; std::string stop_desc; float latitude; double longitude; std::string zone_id; std::string stop_url; std::string location_type;
    while(in.read_row(quaycoderef, stop_code, stop_name, stop_desc, latitude, longitude, zone_id, stop_url, location_type)){
skinkie commented 7 years ago

I noticed that the source data is missing a column. Closing this for now, I'll come with a better example.