From 44a8e9bf35c83b760c2ca4bb13df05474dd833cb Mon Sep 17 00:00:00 2001 From: Niels Date: Sun, 3 Apr 2016 16:33:30 +0200 Subject: [PATCH] locale-independent dump --- src/json.hpp | 10 ++++++++++ src/json.hpp.re2c | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/json.hpp b/src/json.hpp index 0594b38d..8fb400c7 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -2148,6 +2148,7 @@ class basic_json string_t dump(const int indent = -1) const { std::stringstream ss; + ss.imbue(std::locale("C")); if (indent >= 0) { @@ -5653,11 +5654,20 @@ class basic_json const bool pretty_print = (o.width() > 0); const auto indentation = (pretty_print ? o.width() : 0); + // save locale of o + auto old_locale = o.getloc(); + // set locale of o to "C" + o.imbue(std::locale("C")); + // reset width to 0 for subsequent calls to this stream o.width(0); // do the actual serialization j.dump(o, pretty_print, static_cast(indentation)); + + // reset locale + o.imbue(old_locale); + return o; } diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index f4ddacf7..2422ef8b 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -2148,6 +2148,7 @@ class basic_json string_t dump(const int indent = -1) const { std::stringstream ss; + ss.imbue(std::locale("C")); if (indent >= 0) { @@ -5653,11 +5654,20 @@ class basic_json const bool pretty_print = (o.width() > 0); const auto indentation = (pretty_print ? o.width() : 0); + // save locale of o + auto old_locale = o.getloc(); + // set locale of o to "C" + o.imbue(std::locale("C")); + // reset width to 0 for subsequent calls to this stream o.width(0); // do the actual serialization j.dump(o, pretty_print, static_cast(indentation)); + + // reset locale + o.imbue(old_locale); + return o; }