Description
Hi
We're using jsoncpp 1.6.2. on windows 64bit in visual studio 2013.
We (and, I think, many others) use setlocale to set the locale of the program to that of the current user (in Windows).
According to some closed issues on this board, locale issues should be fixed now.
For instance, #89 and #3 to me imply locale issues should be fixed.
However, they aren't.
There is a horrible workaround in the valueToString method that replaces all commas with a period....really ??? That's not a solution, that's a hack.
Furthermore, all decodeDouble methods still use a sscanf call that depends on the current runtime locale.
For instance, this code does not parse the value 1.234 correctly:
setlocale(LC_ALL, "fr-FR"); // change to a locale that uses comma instead of period.
std::string content = "{ \"bla\" : 1.234 }";
std::stringstream s(content);
Json::CharReaderBuilder rbuilder;
rbuilder["collectComments"] = false;
std::string errs;
Json::Value root;
bool ok = Json::parseFromStream(rbuilder, s, &root, &errs);
double value = root["bla"].asDouble();
value will be 1.000000
A correct solution would be using a stringstream solution proposed before, or to use the locale specific variants of sprintf and sscanf.
In VS2013 these are _sprintf_l and _sscanf_l. I don't know if these are available for gcc, maybe you can find out.
Feed those methods a locale specifically created for jsoncpp, for instance with the following method:
_locale_t getJsonLocale()
{
static _locale_t json_locale = _create_locale(LC_ALL, "C");
return json_locale;
}
I would appreciate it if you can take the time to fix this problem once and for all without resorting to assume that everyone uses the same "C"/english locale and without doing string replacements after a printf.....