Skip to content

Commit

Permalink
Get decimal separator from locale if available. It is not always comma.
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Pitka committed Oct 26, 2021
1 parent 94a6220 commit 3a39e27
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/lib_json/json_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,25 @@ 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 <typename Iter> 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 <typename Iter> void fixNumericLocaleInput(Iter begin, Iter end) {
char decimalPoint = getDecimalPoint();
if (decimalPoint == '\0' || decimalPoint == '.') {
return;
}
for (; begin != end; ++begin) {
if (*begin == '.') {
*begin = decimalPoint;
}
}
std::replace(begin, end, '.', decimalPoint);
}

/**
Expand Down

0 comments on commit 3a39e27

Please sign in to comment.