mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-02-25 15:46:03 +01:00
Merge pull request #523 from prezi/fix-android-lconv
Workaround for missing lconv::decimal_point on android
This commit is contained in:
commit
0a97e38ea5
@ -15,6 +15,26 @@
|
|||||||
|
|
||||||
namespace Json {
|
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.
|
/// Converts a unicode code-point to UTF-8.
|
||||||
static inline JSONCPP_STRING codePointToUTF8(unsigned int cp) {
|
static inline JSONCPP_STRING codePointToUTF8(unsigned int cp) {
|
||||||
JSONCPP_STRING result;
|
JSONCPP_STRING result;
|
||||||
@ -84,11 +104,11 @@ static inline void fixNumericLocale(char* begin, char* end) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void fixNumericLocaleInput(char* begin, char* end) {
|
static inline void fixNumericLocaleInput(char* begin, char* end) {
|
||||||
struct lconv* lc = localeconv();
|
char decimalPoint = Locale<struct lconv>::decimalPoint();
|
||||||
if ((lc != NULL) && (*(lc->decimal_point) != '.')) {
|
if (decimalPoint != '\0' && decimalPoint != '.') {
|
||||||
while (begin < end) {
|
while (begin < end) {
|
||||||
if (*begin == '.') {
|
if (*begin == '.') {
|
||||||
*begin = *(lc->decimal_point);
|
*begin = decimalPoint;
|
||||||
}
|
}
|
||||||
++begin;
|
++begin;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user