ben-strasser / fast-cpp-csv-parser

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

can we not ignore comment #104

Closed mom1705 closed 3 years ago

mom1705 commented 4 years ago

I am having really hard time writing code using csvparse because of lack of examples. I want "#" in the starting of the line NOT to be considered as comment and I wrote

io::CSVReader<3, io::no_comment> in(strFileName.c_str());

and tried io::CSVReader<3, io::no_comment<'#'>> in(strFileName.c_str());

and it gives compilation error

/fgw_dev/dev/libs/saxparser/include/csv.h:875:77: error: 'trim' is not a member of 'io::no_comment' trim_policy::trim(col_begin, col_end);

mom1705 commented 4 years ago

io::CSVReader<3> in(strFileName.c_str()); works but if csv file has any line starting "#", it is not considered invalid/error which is my requirement.

ben-strasser commented 4 years ago

If all you want is to read normal CSV files, use

io::CSVReader<3> in(strFileName.c_str());

otherwise look at the readme, which tells you the order of the arguments and gives examples. The first argument after the number of columns is the trim policy. The compiler is complaining that is cannot trim using the no_comment policy, which is the case, because the no_comment policy does not control trimming.

mom1705 commented 4 years ago

I did read README and after that I tried

io::CSVReader<3, io::trim_chars<' '>,io::no_comment<'#'>> in(strFileName.c_str());

but it gave error /fgw_dev/dev/libs/saxparser/include/csv.h:876:82: error: 'unescape' is not a member of 'io::no_comment' quote_policy::unescape(col_begin, col_end); ^

my requirement is simple, I don't want to support "#" ( used for comment) and want it to throw error which I want to catch. Can u pls help

ben-strasser commented 4 years ago

Is

CSVReader<3, trim_chars<' ', '\t'>, no_quote_escape<','>, throw_on_overflow, single_line_comment<'#'>>

what you want?

Apparently, the throw_in_overflow is missing in the readme.

mom1705 commented 4 years ago

Thanks Ben, Can you pls. explain what will
CSVReader<3, trim_chars<' ', '\t'>, no_quote_escape<','>, throw_on_overflow, single_line_comment<'#'>>

do ? will it throw "on_overflow" error ? atleast it compiled. Now let me see what does it do?

ben-strasser commented 4 years ago

Please, give the documentation another read.

You have 5 template parameters. These must appear in the right order. If you omit a parameter the default is used. What the overflow_policy does govern what happens when there is an overflow. The example I have given you throws when there is an overflow.

mom1705 commented 4 years ago

sure, thanks a lot.