From 496c6555239e90f995bbb09ad48e17afa8058719 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 10 Jul 2014 20:22:47 -0700 Subject: [PATCH] fix numeric locale In some locales (e.g. de_DE) floats have commas instead of dots, but JSON requires dots. See: https://github.com/open-source-parsers/jsoncpp/pull/9 https://github.com/open-source-parsers/jsoncpp/pull/3 --- src/lib_json/json_tool.h | 14 ++++++++++++++ src/lib_json/json_writer.cpp | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib_json/json_tool.h b/src/lib_json/json_tool.h index c18a768..9f2b534 100644 --- a/src/lib_json/json_tool.h +++ b/src/lib_json/json_tool.h @@ -68,6 +68,20 @@ static inline void uintToString(LargestUInt value, char *¤t) { } while (value != 0); } +/** Change ',' to '.' everywhere in buffer. + * + * We had a sophisticated way, but it did not work in WinCE. + * @see https://github.com/open-source-parsers/jsoncpp/pull/9 + */ +static inline void fixNumericLocale(char* begin, char* end) { + while (begin < end) { + if (*begin == ',') { + *begin = '.'; + } + ++begin; + } +} + } // namespace Json { #endif // LIB_JSONCPP_JSON_TOOL_H_INCLUDED diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 52ecf3e..1abcc93 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -77,7 +77,7 @@ std::string valueToString(double value) { #else snprintf(buffer, sizeof(buffer), "%.16g", value); #endif - + fixNumericLocale(buffer, buffer + strlen(buffer)); return buffer; }