ben-strasser / fast-cpp-csv-parser

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

CSV file with missing column not parseable #75

Open supipd opened 5 years ago

supipd commented 5 years ago

Perhaps my misconception, but fast-cpp-csv-parser is not able to parse CSV file with missing separators at rows end. Maybe CSV not exact according standarts, but in practice is often used

test.csv

a;b;c
1;2;3
1;2;
1;2
1;;
1;
1

main.c

int main(int argc, char** argv)
{
    io::CSVReader<3, io::trim_chars<' ', '\t'>, io::no_quote_escape<';'>> in("test.csv");
    in.read_header(io::ignore_extra_column, "a", "b", "c");
    std::string vendor, size, speed;
    try {
        while(in.read_row(vendor, size, speed)){
            // do stuff with the data
        }
        cout << "ignore_extra_column OK" << endl;
    } catch(exception &e) {
        cout << "ignore_extra_column BAD" << endl;
    }
    io::CSVReader<3, io::trim_chars<' ', '\t'>, io::no_quote_escape<';'>> in1("test.csv");
    in1.read_header(io::ignore_missing_column, "a", "b", "c");
    try {
        while(in.read_row(vendor, size, speed)){
            // do stuff with the data
        }
        cout << "ignore_missing_column OK" << endl;
    } catch(exception &e) {
        cout << "ignore_missing_column BAD" << endl;
    }
    io::CSVReader<3, io::trim_chars<' ', '\t'>, io::no_quote_escape<';'>> in2("test.csv");
    in2.read_header(io::ignore_no_column, "a", "b", "c");
    try {
        while(in.read_row(vendor, size, speed)){           
               // do stuff with the data
        }
        cout << "ignore_no_column OK" << endl;
    } catch(exception &e) {
        cout << "ignore_no_column BAD" << endl;
    }
}

output:

ignore_extra_column BAD ignore_missing_column BAD ignore_no_column BAD

TedPoch commented 4 years ago

Hate to bring up old issues, but I'm having a very similar issue. I suspect I'm doing something wrong, or missing something essential from the documentation. Was there a solution discussed offline for the above issue?