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
This commit is contained in:
Vadim Zeitlin
2010-05-31 11:55:41 +00:00
parent 1a39b0131f
commit 105993f7b6
2 changed files with 51 additions and 3 deletions

View File

@@ -2280,7 +2280,6 @@ public:
// convert to a double // convert to a double
bool ToDouble(double *val) const; bool ToDouble(double *val) const;
#if wxUSE_XLOCALE
// conversions to numbers using C locale // conversions to numbers using C locale
// convert to a signed integer // convert to a signed integer
bool ToCLong(long *val, int base = 10) const; bool ToCLong(long *val, int base = 10) const;
@@ -2288,7 +2287,6 @@ public:
bool ToCULong(unsigned long *val, int base = 10) const; bool ToCULong(unsigned long *val, int base = 10) const;
// convert to a double // convert to a double
bool ToCDouble(double *val) const; bool ToCDouble(double *val) const;
#endif
#ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
// formatted input/output // formatted input/output

View File

@@ -24,6 +24,7 @@
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/string.h" #include "wx/string.h"
#include "wx/wxcrtvararg.h" #include "wx/wxcrtvararg.h"
#include "wx/intl.h"
#include "wx/log.h" #include "wx/log.h"
#endif #endif
@@ -1733,7 +1734,56 @@ bool wxString::ToCDouble(double *pVal) const
WX_STRING_TO_X_TYPE_END 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 // formatted output