Skip to content

Commit 52cfe5a

Browse files
committed
Replaced the template-based solution for avoiding calls to localeconv() with a macro-based one (fixes open-source-parsers#527)
1 parent a304d61 commit 52cfe5a

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

src/lib_json/json_tool.h

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
#ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED
77
#define LIB_JSONCPP_JSON_TOOL_H_INCLUDED
8+
9+
#ifndef NO_LOCALE_SUPPORT
810
#include <clocale>
11+
#endif
912

1013
/* This header provides common string manipulation support, such as UTF-8,
1114
* portable conversion from/to string...
@@ -14,26 +17,14 @@
1417
*/
1518

1619
namespace Json {
17-
18-
/// Fallback for decimal_point on android, where the lconv is an empty struct.
19-
template<typename Lconv, bool=(sizeof(Lconv) >= sizeof(char*))>
20-
struct Locale {
21-
static char decimalPoint() {
22-
return '\0';
23-
}
24-
};
25-
26-
/// Return decimal_point for the current locale.
27-
template<typename Lconv>
28-
struct Locale<Lconv, true> {
29-
static char decimalPoint() {
30-
Lconv* lc = localeconv();
31-
if (lc == NULL) {
32-
return '\0';
33-
}
34-
return *(lc->decimal_point);
35-
}
36-
};
20+
static char getDecimalPoint() {
21+
#ifdef NO_LOCALE_SUPPORT
22+
return '\0';
23+
#else
24+
struct lconv* lc = localeconv();
25+
return lc ? *(lc->decimal_point) : '\0';
26+
#endif
27+
}
3728

3829
/// Converts a unicode code-point to UTF-8.
3930
static inline JSONCPP_STRING codePointToUTF8(unsigned int cp) {
@@ -104,7 +95,7 @@ static inline void fixNumericLocale(char* begin, char* end) {
10495
}
10596

10697
static inline void fixNumericLocaleInput(char* begin, char* end) {
107-
char decimalPoint = Locale<struct lconv>::decimalPoint();
98+
char decimalPoint = getDecimalPoint();
10899
if (decimalPoint != '\0' && decimalPoint != '.') {
109100
while (begin < end) {
110101
if (*begin == '.') {

0 commit comments

Comments
 (0)