Skip to content

Commit 49c7326

Browse files
committed
Revert "Merge pull request open-source-parsers#7 from steffen-kiess/fix-locale"
This reverts commit 0db9d6e, reversing changes made to 06dcb1f. For discussion, see open-source-parsers#9 open-source-parsers#3
1 parent 655a9db commit 49c7326

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/lib_json/json_writer.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,22 @@ std::string valueToString(UInt value) {
6363
#endif // # if defined(JSON_HAS_INT64)
6464

6565
std::string valueToString(double value) {
66-
// We need not request the alternative representation
67-
// that always has a decimal point because JSON doesn't distingish the
68-
// concepts of reals and integers.
69-
std::stringstream str;
70-
// Set locale to "C" to always get a '.' instead of a ','
71-
str.imbue(std::locale::classic());
72-
str.precision(16);
73-
str << value;
74-
return str.str();
66+
// Allocate a buffer that is more than large enough to store the 16 digits of
67+
// precision requested below.
68+
char buffer[32];
69+
70+
// Print into the buffer. We need not request the alternative representation
71+
// that always has a decimal point because JSON doesn't distingish the
72+
// concepts of reals and integers.
73+
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with
74+
// visual studio 2005 to
75+
// avoid warning.
76+
sprintf_s(buffer, sizeof(buffer), "%.16g", value);
77+
#else
78+
snprintf(buffer, sizeof(buffer), "%.16g", value);
79+
#endif
80+
81+
return buffer;
7582
}
7683

7784
std::string valueToString(bool value) { return value ? "true" : "false"; }

0 commit comments

Comments
 (0)