Skip to content

Commit 094a7d8

Browse files
committed
Fix locale for decimal points
resolves open-source-parsers#514
1 parent b9afdf1 commit 094a7d8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/lib_json/json_reader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,7 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) {
16191619
Char buffer[bufferSize + 1];
16201620
memcpy(buffer, token.start_, ulength);
16211621
buffer[length] = 0;
1622+
fixNumericLocaleInput(buffer, buffer + length);
16221623
count = sscanf(buffer, format, &value);
16231624
} else {
16241625
JSONCPP_STRING buffer(token.start_, token.end_);

src/lib_json/json_tool.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED
77
#define LIB_JSONCPP_JSON_TOOL_H_INCLUDED
8+
#include <clocale>
89

910
/* This header provides common string manipulation support, such as UTF-8,
1011
* portable conversion from/to string...
@@ -82,6 +83,18 @@ static inline void fixNumericLocale(char* begin, char* end) {
8283
}
8384
}
8485

86+
static inline void fixNumericLocaleInput(char* begin, char* end) {
87+
struct lconv* lc = localeconv();
88+
if ((lc != NULL) && (*(lc->decimal_point) != '.')) {
89+
while (begin < end) {
90+
if (*begin == '.') {
91+
*begin = *(lc->decimal_point);
92+
}
93+
++begin;
94+
}
95+
}
96+
}
97+
8598
} // namespace Json {
8699

87100
#endif // LIB_JSONCPP_JSON_TOOL_H_INCLUDED

0 commit comments

Comments
 (0)