From: Vadim Zeitlin Date: Mon, 31 May 2010 11:55:41 +0000 (+0000) Subject: Make wxString::ToCXXX() methods always available. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/105993f7b6baf97b596d09e9c59c42adcee0dbcf Make wxString::ToCXXX() methods always available. We use these methods inside wxWidgets itself and so want to always have them, even when wxUSE_XLOCALE==0. Provide replacement manual implementations for this case. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64448 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/string.h b/include/wx/string.h index 5d207a6b7f..369d30c505 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -2280,7 +2280,6 @@ public: // convert to a double bool ToDouble(double *val) const; -#if wxUSE_XLOCALE // conversions to numbers using C locale // convert to a signed integer bool ToCLong(long *val, int base = 10) const; @@ -2288,7 +2287,6 @@ public: bool ToCULong(unsigned long *val, int base = 10) const; // convert to a double bool ToCDouble(double *val) const; -#endif #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN // formatted input/output diff --git a/src/common/string.cpp b/src/common/string.cpp index f3e8c0b260..952727ec62 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -24,6 +24,7 @@ #ifndef WX_PRECOMP #include "wx/string.h" #include "wx/wxcrtvararg.h" + #include "wx/intl.h" #include "wx/log.h" #endif @@ -1733,7 +1734,56 @@ bool wxString::ToCDouble(double *pVal) const WX_STRING_TO_X_TYPE_END } -#endif // wxUSE_XLOCALE +#else // wxUSE_XLOCALE + +// Provide implementation of these functions even when wxUSE_XLOCALE is +// disabled, we still need them in wxWidgets internal code. + +// For integers we just assume the current locale uses the same number +// representation as the C one as there is nothing else we can do. +bool wxString::ToCLong(long *pVal, int base) const +{ + return ToLong(pVal, base); +} + +bool wxString::ToCULong(unsigned long *pVal, int base) const +{ + return ToULong(pVal, base); +} + +// For floating point numbers we have to handle the problem of the decimal +// point which is different in different locales. +bool wxString::ToCDouble(double *pVal) const +{ + // Create a copy of this string using the decimal point instead of whatever + // separator the current locale uses. +#if wxUSE_INTL + wxString sep = wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, + wxLOCALE_CAT_NUMBER); + if ( sep == "." ) + { + // We can avoid an unnecessary string copy in this case. + return ToDouble(pVal); + } +#else // !wxUSE_INTL + // We don't know what the current separator is so it might even be a point + // already, try to parse the string as a double: + if ( ToDouble(pVal) ) + { + // It must have been the point, nothing else to do. + return true; + } + + // Try to guess the separator, using the most common alternative value. + wxString sep(","); +#endif // wxUSE_INTL/!wxUSE_INTL + wxString cstr(*this); + cstr.Replace(".", sep); + + return cstr.ToDouble(pVal); +} + +#endif // wxUSE_XLOCALE/!wxUSE_XLOCALE // --------------------------------------------------------------------------- // formatted output