Get decimal separator from locale if available. It is not always comma.

This commit is contained in:
Petr Pitka 2021-10-05 15:29:06 +02:00
parent 5defb4ed1a
commit 77733c280d

View File

@ -86,18 +86,17 @@ static inline void uintToString(LargestUInt value, char*& current) {
} while (value != 0); } 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. * We had a sophisticated way, but it did not work in WinCE.
* @see https://github.com/open-source-parsers/jsoncpp/pull/9 * @see https://github.com/open-source-parsers/jsoncpp/pull/9
*/ */
template <typename Iter> Iter fixNumericLocale(Iter begin, Iter end) { template <typename Iter> Iter fixNumericLocale(Iter begin, Iter end) {
for (; begin != end; ++begin) { const char decimalPoint = getDecimalPoint();
if (*begin == ',') { if (decimalPoint != '\0' && decimalPoint != '.') {
*begin = '.'; std::replace(begin, end, decimalPoint, '.');
} }
} return end;
return begin;
} }
template <typename Iter> void fixNumericLocaleInput(Iter begin, Iter end) { template <typename Iter> void fixNumericLocaleInput(Iter begin, Iter end) {
@ -105,11 +104,7 @@ template <typename Iter> void fixNumericLocaleInput(Iter begin, Iter end) {
if (decimalPoint == '\0' || decimalPoint == '.') { if (decimalPoint == '\0' || decimalPoint == '.') {
return; return;
} }
for (; begin != end; ++begin) { std::replace(begin, end, '.', decimalPoint);
if (*begin == '.') {
*begin = decimalPoint;
}
}
} }
/** /**