Skip to content

Commit

Permalink
Replaced the template-based solution for avoiding calls to localeconv…
Browse files Browse the repository at this point in the history
…() with a macro-based one (fixes open-source-parsers#527)
  • Loading branch information
DrMetallius committed Sep 6, 2016
1 parent a304d61 commit 52cfe5a
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/lib_json/json_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

#ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED
#define LIB_JSONCPP_JSON_TOOL_H_INCLUDED

#ifndef NO_LOCALE_SUPPORT
#include <clocale>
#endif

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

namespace Json {

/// Fallback for decimal_point on android, where the lconv is an empty struct.
template<typename Lconv, bool=(sizeof(Lconv) >= sizeof(char*))>
struct Locale {
static char decimalPoint() {
return '\0';
}
};

/// Return decimal_point for the current locale.
template<typename Lconv>
struct Locale<Lconv, true> {
static char decimalPoint() {
Lconv* lc = localeconv();
if (lc == NULL) {
return '\0';
}
return *(lc->decimal_point);
}
};
static char getDecimalPoint() {
#ifdef NO_LOCALE_SUPPORT
return '\0';
#else
struct lconv* lc = localeconv();
return lc ? *(lc->decimal_point) : '\0';
#endif
}

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

static inline void fixNumericLocaleInput(char* begin, char* end) {
char decimalPoint = Locale<struct lconv>::decimalPoint();
char decimalPoint = getDecimalPoint();
if (decimalPoint != '\0' && decimalPoint != '.') {
while (begin < end) {
if (*begin == '.') {
Expand Down

0 comments on commit 52cfe5a

Please sign in to comment.