ben-strasser / fast-cpp-csv-parser

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

Optional Values #47

Closed benjamin0 closed 7 years ago

benjamin0 commented 7 years ago

I have a .csv file with data that looks like the following:

a,b,c
1,2,3
1,,3
1,2,3

I'd like to know that there's no b value for the second line (rather than interpreting it as 0). Is it possible to do this?

ben-strasser commented 7 years ago

Hi,

does the following code work for you?

int a, b, c; charb_str; while(in.read_row(a,b_str,c)){ if(b_str == '\0'){ // No b } else { b = atoi(b_str); // there is a b } }

Best Regards Ben Strasser

On 07/11/2017 12:22 AM, Ben Segal wrote:

I have a |.csv| file with data that looks like the following:

|a,b,c 1,2,3 1,,3 1,2,3 |

I'd like to know that there's no |b| value for the second line (rather than interpreting it as |0|). Is it possible to do this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ben-strasser/fast-cpp-csv-parser/issues/47, or mute the thread https://github.com/notifications/unsubscribe-auth/ALaAj7AmzL663O_LoRGakYDmwkJpVpFaks5sMqQ-gaJpZM4OTflq.

DonaldTrump88 commented 7 years ago

I would like to know what will happen in case of 'b' value is not present.

  1. Will the library throw error or issue just warning?
  2. Is there any option to enable or disable these behaviours?
ben-strasser commented 7 years ago

As stated in the top comment: The default is interpret an empty field as zero value. If you want something else you must read a char* and do the parsing yourself.