vincentlaucsb / csv-parser

A high-performance, fully-featured CSV parser and serializer for modern C++.
MIT License
864 stars 144 forks source link

CSVField: new member function try_parse_decimal() to specify one or more decimal symbols #226

Closed wilfz closed 1 month ago

wilfz commented 1 month ago

I much appreciate your library. But in most european countries the decimal separator is comma ',' and not dot ','. The trivial solution would be to add just "case ',':" in internals::data_type(). But that might break existing applications that rely on '.' and nothing else as decimal symbol. On the other hand a static member "string _decimalpoints;" in CSVField would do the thing but changing that at runtime would break multithreading safety. So I added another member function try_parse_decimal()similar to try_parse_hex()except that it also sets the private members _type and value.

vincentlaucsb commented 1 month ago

Thanks for your PR and for bringing the comma vs dot issue to my attention. I'll take a closer look at this when I have time.

wilfz commented 1 month ago

just added the case '+': to try_convert() decimal(), too

vincentlaucsb commented 1 month ago

First off, I appreciate you making a PR to improve this library that minimizes breaking changes.

I agree the CSVField methods should be more tolerant of non-imperial decimal number representations.

However, here's the changes I would like to see:

wilfz commented 1 month ago

Hello Vincent. Thanks for your kind reply.

wilfz commented 1 month ago

I reworked try_parse_decimal() and added the optional parameter const char decimalsymbol = '.' to the internal function data_type().

vincentlaucsb commented 1 month ago

Wrote some unit tests on my end and your changes are passing them just fine. Thanks again for your contribution.