Skip to content

Commit 0a97e38

Browse files
authored
Merge pull request #523 from prezi/fix-android-lconv
Workaround for missing lconv::decimal_point on android
2 parents 126bdc2 + 894e78b commit 0a97e38

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/lib_json/json_tool.h

+23-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@
1515

1616
namespace Json {
1717

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+
};
37+
1838
/// Converts a unicode code-point to UTF-8.
1939
static inline JSONCPP_STRING codePointToUTF8(unsigned int cp) {
2040
JSONCPP_STRING result;
@@ -84,11 +104,11 @@ static inline void fixNumericLocale(char* begin, char* end) {
84104
}
85105

86106
static inline void fixNumericLocaleInput(char* begin, char* end) {
87-
struct lconv* lc = localeconv();
88-
if ((lc != NULL) && (*(lc->decimal_point) != '.')) {
107+
char decimalPoint = Locale<struct lconv>::decimalPoint();
108+
if (decimalPoint != '\0' && decimalPoint != '.') {
89109
while (begin < end) {
90110
if (*begin == '.') {
91-
*begin = *(lc->decimal_point);
111+
*begin = decimalPoint;
92112
}
93113
++begin;
94114
}

0 commit comments

Comments
 (0)