From 744ea8a61803a74ac66c02417a1b454765068226 Mon Sep 17 00:00:00 2001 From: Mariano Reingart Date: Wed, 11 Feb 2015 04:36:24 +0000 Subject: [PATCH] For Android (wxQT), add private wcstol, wcstoul and wcstod These functions are needed by wxString::ToLong wxString::ToDouble etc.. They do exist in the android library, but do not work corretly. This change implements them using strtol strtoul and strtod For more info see discussion in wx-dev list: https://groups.google.com/d/msg/wx-dev/71qtIFcujgM/TRCfCjGHUhEJ Thanks @seandepagnier (modified a bit the comments) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78472 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/wxcrtbase.h | 12 +++++++++++ src/common/wxcrt.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/include/wx/wxcrtbase.h b/include/wx/wxcrtbase.h index cabd03ddd4..044759d4d3 100644 --- a/include/wx/wxcrtbase.h +++ b/include/wx/wxcrtbase.h @@ -197,9 +197,21 @@ WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size ); #define wxCRT_StrtodA strtod #define wxCRT_StrtolA strtol #define wxCRT_StrtoulA strtoul + +#ifdef __ANDROID__ // these functions are broken on android + +extern double android_wcstod(const wchar_t *nptr, wchar_t **endptr); +extern long android_wcstol(const wchar_t *nptr, wchar_t **endptr, int base); +extern unsigned long android_wcstoul(const wchar_t *nptr, wchar_t **endptr, int base); + +#define wxCRT_StrtodW android_wcstod +#define wxCRT_StrtolW android_wcstol +#define wxCRT_StrtoulW android_wcstoul +#else #define wxCRT_StrtodW wcstod #define wxCRT_StrtolW wcstol #define wxCRT_StrtoulW wcstoul +#endif #ifdef __VISUALC__ #define wxCRT_StrtollA _strtoi64 diff --git a/src/common/wxcrt.cpp b/src/common/wxcrt.cpp index d44bea4594..bd0515c477 100644 --- a/src/common/wxcrt.cpp +++ b/src/common/wxcrt.cpp @@ -1268,3 +1268,49 @@ int wxVsscanf(const wxCStrData& str, const char *format, va_list ap) int wxVsscanf(const wxCStrData& str, const wchar_t *format, va_list ap) { return wxCRT_VsscanfW(str.AsWCharBuf(), format, ap); } #endif // HAVE_NO_VSSCANF + +// ============================================================================ +// ANDROID specific private implementations (due stubs/missing support in NDK) +// ============================================================================ + +// On android, most wchar_t functions are broken, so instead we must +// convert a byte at a time + +#ifdef __ANDROID__ +#define ANDROID_WCSTO_START \ + int len = wcslen(nptr) + 1; \ + char dst[len]; \ + for(int i=0; i