Unable to parse numbers if std::locale() changes the decimal
Describe the bug
Hi, I'm not living in an English speaking country and as such I naturally set std::locale("") to make cpp use familiar number representations instead (This changes the decimal from a dot to a comma). There seems to be a problem where jsoncpp uses a string stream to parse decimals, and the input stream correctly uses the default locale set before, but this now differs from the locale required by Json.
To Reproduce Steps to reproduce the behavior:
- std::locale::global(std::locale("de_DE.UTF-8"));
- jsonReader.parse("[123.45]", root, false);
Expected behavior Should parse the number with dot as decimal without any issue.
Desktop (please complete the following information):
- OS: Linux
- Meson N/A
- Ninja N/A
Additional context
The solution is to imbue the streams with the local required by json like is.imbue(std::local("en_US.UTF-8")) for the reader:
https://github.com/open-source-parsers/jsoncpp/blob/89e2973c754a9c02a49974d839779b151e95afd6/src/lib_json/json_reader.cpp#L590
https://github.com/open-source-parsers/jsoncpp/blob/89e2973c754a9c02a49974d839779b151e95afd6/src/lib_json/json_reader.cpp#L1624
Don't currently know if the writer is affected with sprintf: https://github.com/open-source-parsers/jsoncpp/blob/89e2973c754a9c02a49974d839779b151e95afd6/src/lib_json/json_writer.cpp#L127
Workaround is to temporarily set the locale to en_US manually