Skip to content

Workaround for missing lconv::decimal_point on android #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/lib_json/json_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@

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);
}
};

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

static inline void fixNumericLocaleInput(char* begin, char* end) {
struct lconv* lc = localeconv();
if ((lc != NULL) && (*(lc->decimal_point) != '.')) {
char decimalPoint = Locale<struct lconv>::decimalPoint();
if (decimalPoint != '\0' && decimalPoint != '.') {
while (begin < end) {
if (*begin == '.') {
*begin = *(lc->decimal_point);
*begin = decimalPoint;
}
++begin;
}
Expand Down