Closed Xfel closed 5 years ago
So, it seems that the locale switch was actually caused by another library I'm using. According to the C++ documentation, the locale is initialized in a deterministic state. Unless you change it, it works.
This issue does not only affect mesh parsing, but parsing of floating point numbers in general, including the graph files and the physics config files for vortex. All of these are locale independent formats, so parsing them should be locale independent as well. One solution would be to reset the locale in every parsing function.
I just found this discussion which is very similar to this issue: https://github.com/robotology/idyntree/issues/288
Now there is a function String_toDouble_l() that does the conversion with the C locale (dot separator independent of applications's locale). It is based on the strtod_l() function, which seems to be about an order of magnitude faster than the imbued stringstream. This is now being used in the parsing functions for meshes and Rcs-related xml files. It works fine for a few tests I did, and can be tested with a "-locale" option in the Rcs program.
Here are a few points I'm currently not sure about:
I guess for printing out stuff (printf, sprintf etc.) we stick to the program's locale, and accept a comma instead of a dot. This however has implications when writing out a xml file, since that will also contain commas for some locales. This means that when writing a file with a "comma" locale, it will wrongly be parsed in. Or should we make a difference for writing out xml files?
How to deal with arrays of numbers, e.g. in matrices, BVH trajectories etc. Should these follow the application's locale, or should we also enforce the C locale? In the latter case, the same issue as in 1) applies
Any ideas / suggestions welcome
I think that we should use the system locale when printing to console (it's easier), but the C locale when writing a file.
Sounds reasonable, should be all in place now.
The parser for .tri files uses sscanf to read floating point values. On other locales like ie german, the decimal separator is a , instaed of a . which breaks parsing the mesh files whose format is fixed.