From 77733c280da49ce123b9456becd8cf012f8a3fb3 Mon Sep 17 00:00:00 2001 From: Petr Pitka Date: Tue, 5 Oct 2021 15:29:06 +0200 Subject: [PATCH] Get decimal separator from locale if available. It is not always comma. --- src/lib_json/json_tool.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/lib_json/json_tool.h b/src/lib_json/json_tool.h index b952c19..1222866 100644 --- a/src/lib_json/json_tool.h +++ b/src/lib_json/json_tool.h @@ -86,18 +86,17 @@ static inline void uintToString(LargestUInt value, char*& current) { } while (value != 0); } -/** Change ',' to '.' everywhere in buffer. +/** Change decimal point from current locale (i.e. ',') 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 */ template Iter fixNumericLocale(Iter begin, Iter end) { - for (; begin != end; ++begin) { - if (*begin == ',') { - *begin = '.'; - } + const char decimalPoint = getDecimalPoint(); + if (decimalPoint != '\0' && decimalPoint != '.') { + std::replace(begin, end, decimalPoint, '.'); } - return begin; + return end; } template void fixNumericLocaleInput(Iter begin, Iter end) { @@ -105,11 +104,7 @@ template void fixNumericLocaleInput(Iter begin, Iter end) { if (decimalPoint == '\0' || decimalPoint == '.') { return; } - for (; begin != end; ++begin) { - if (*begin == '.') { - *begin = decimalPoint; - } - } + std::replace(begin, end, '.', decimalPoint); } /**