Revert "Merge pull request #7 from steffen-kiess/fix-locale"

This reverts commit 0db9d6ea013792b010c598c2a9a3a9e39a2decd9, reversing
changes made to 06dcb1fc8922991919887e229fdd741bccde0dfa.

For discussion, see
  https://github.com/open-source-parsers/jsoncpp/pull/9
  https://github.com/open-source-parsers/jsoncpp/pull/3
This commit is contained in:
Christopher Dunn 2014-07-10 19:58:05 -07:00
parent 655a9db0cc
commit 49c732607b

View File

@ -63,15 +63,22 @@ std::string valueToString(UInt value) {
#endif // # if defined(JSON_HAS_INT64)
std::string valueToString(double value) {
// We need not request the alternative representation
// that always has a decimal point because JSON doesn't distingish the
// concepts of reals and integers.
std::stringstream str;
// Set locale to "C" to always get a '.' instead of a ','
str.imbue(std::locale::classic());
str.precision(16);
str << value;
return str.str();
// Allocate a buffer that is more than large enough to store the 16 digits of
// precision requested below.
char buffer[32];
// Print into the buffer. We need not request the alternative representation
// that always has a decimal point because JSON doesn't distingish the
// concepts of reals and integers.
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with
// visual studio 2005 to
// avoid warning.
sprintf_s(buffer, sizeof(buffer), "%.16g", value);
#else
snprintf(buffer, sizeof(buffer), "%.16g", value);
#endif
return buffer;
}
std::string valueToString(bool value) { return value ? "true" : "false"; }