]> git.saurik.com Git - wxWidgets.git/commitdiff
Make wxString::ToCXXX() methods always available.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 31 May 2010 11:55:41 +0000 (11:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 31 May 2010 11:55:41 +0000 (11:55 +0000)
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

include/wx/string.h
src/common/string.cpp

index 5d207a6b7fd52d8a41dca1d1d8b27e86df8e01e5..369d30c5056b552274fef40a24de7bb6d30e5f54 100644 (file)
@@ -2280,7 +2280,6 @@ public:
       // convert to a double
   bool ToDouble(double *val) const;
 
       // 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;
   // 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;
   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
 
 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
   // formatted input/output
index f3e8c0b2605001575d1cbbf725356aa4011e5ab9..952727ec6263d18a355c763c6c029d0bc8c465ef 100644 (file)
@@ -24,6 +24,7 @@
 #ifndef WX_PRECOMP
     #include "wx/string.h"
     #include "wx/wxcrtvararg.h"
 #ifndef WX_PRECOMP
     #include "wx/string.h"
     #include "wx/wxcrtvararg.h"
+    #include "wx/intl.h"
     #include "wx/log.h"
 #endif
 
     #include "wx/log.h"
 #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