From 52cfe5ae889adf0c4099b16ddeb4b529b1f09007 Mon Sep 17 00:00:00 2001 From: Alexander Gazarov Date: Tue, 6 Sep 2016 14:39:59 +0300 Subject: [PATCH] Replaced the template-based solution for avoiding calls to localeconv() with a macro-based one (fixes #527) --- src/lib_json/json_tool.h | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/lib_json/json_tool.h b/src/lib_json/json_tool.h index 4a829b0..0e729e6 100644 --- a/src/lib_json/json_tool.h +++ b/src/lib_json/json_tool.h @@ -5,7 +5,10 @@ #ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED #define LIB_JSONCPP_JSON_TOOL_H_INCLUDED + +#ifndef NO_LOCALE_SUPPORT #include +#endif /* This header provides common string manipulation support, such as UTF-8, * portable conversion from/to string... @@ -14,26 +17,14 @@ */ namespace Json { - -/// Fallback for decimal_point on android, where the lconv is an empty struct. -template= sizeof(char*))> -struct Locale { - static char decimalPoint() { - return '\0'; - } -}; - -/// Return decimal_point for the current locale. -template -struct Locale { - 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) { @@ -104,7 +95,7 @@ static inline void fixNumericLocale(char* begin, char* end) { } static inline void fixNumericLocaleInput(char* begin, char* end) { - char decimalPoint = Locale::decimalPoint(); + char decimalPoint = getDecimalPoint(); if (decimalPoint != '\0' && decimalPoint != '.') { while (begin < end) { if (*begin == '.') {