]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
Correct signature of HitTest()
[wxWidgets.git] / src / common / string.cpp
index d154b3c937c1b28bda7e92c94cee00f6e0ab96f3..a791562d7e25fd40ebda91a5289debf9bc56c8b2 100644 (file)
@@ -1391,49 +1391,46 @@ int wxString::Find(wxUniChar ch, bool bFromEnd) const
 // it out. Note that number extraction works correctly on UTF-8 strings, so
 // we can use wxStringCharType and wx_str() for maximum efficiency.
 
-template <typename T>
-bool wxStringToIntType(const wxStringCharType *start,
-                       T *val,
-                       int base,
-                       T (*func)(const wxStringCharType*, wxStringCharType**, int))
-{
-    wxCHECK_MSG( val, false, _T("NULL output pointer") );
-    wxASSERT_MSG( !base || (base > 1 && base <= 36), _T("invalid base") );
-
 #ifndef __WXWINCE__
-    errno = 0;
+    #define DO_IF_NOT_WINCE(x) x
+#else
+    #define DO_IF_NOT_WINCE(x)
 #endif
 
-    wxStringCharType *end;
-    *val = (*func)(start, &end, base);
-
-    // return true only if scan was stopped by the terminating NUL and if the
-    // string was not empty to start with and no under/overflow occurred
-    return !*end && (end != start)
-#ifndef __WXWINCE__
-        && (errno != ERANGE)
-#endif
-    ;
-}
+#define WX_STRING_TO_INT_TYPE(val, base, func)                              \
+    wxCHECK_MSG( val, false, _T("NULL output pointer") );                   \
+    wxASSERT_MSG( !base || (base > 1 && base <= 36), _T("invalid base") );  \
+                                                                            \
+    DO_IF_NOT_WINCE( errno = 0; )                                           \
+                                                                            \
+    const wxStringCharType *start = wx_str();                               \
+    wxStringCharType *end;                                                  \
+    *val = func(start, &end, base);                                         \
+                                                                            \
+    /* return true only if scan was stopped by the terminating NUL and */   \
+    /* if the string was not empty to start with and no under/overflow */   \
+    /* occurred: */                                                         \
+    return !*end && (end != start)                                          \
+        DO_IF_NOT_WINCE( && (errno != ERANGE) )
 
 bool wxString::ToLong(long *val, int base) const
 {
-    return wxStringToIntType(wx_str(), val, base, wxStrtol);
+    WX_STRING_TO_INT_TYPE(val, base, wxStrtol);
 }
 
 bool wxString::ToULong(unsigned long *val, int base) const
 {
-    return wxStringToIntType(wx_str(), val, base, wxStrtoul);
+    WX_STRING_TO_INT_TYPE(val, base, wxStrtoul);
 }
 
 bool wxString::ToLongLong(wxLongLong_t *val, int base) const
 {
-    return wxStringToIntType(wx_str(), val, base, wxStrtoll);
+    WX_STRING_TO_INT_TYPE(val, base, wxStrtoll);
 }
 
 bool wxString::ToULongLong(wxULongLong_t *val, int base) const
 {
-    return wxStringToIntType(wx_str(), val, base, wxStrtoull);
+    WX_STRING_TO_INT_TYPE(val, base, wxStrtoull);
 }
 
 bool wxString::ToDouble(double *val) const
@@ -1832,3 +1829,32 @@ wxString wxString::Upper() const
 
 // convert to lower case, return the copy of the string
 wxString wxString::Lower() const { wxString s(*this); return s.MakeLower(); }
+
+// ----------------------------------------------------------------------------
+// wxUTF8StringBuffer
+// ----------------------------------------------------------------------------
+
+#if wxUSE_UNICODE_WCHAR
+wxUTF8StringBuffer::~wxUTF8StringBuffer()
+{
+    wxMBConvStrictUTF8 conv;
+    size_t wlen = conv.ToWChar(NULL, 0, m_buf);
+    wxCHECK_RET( wlen != wxCONV_FAILED, "invalid UTF-8 data in string buffer?" );
+
+    wxStringInternalBuffer wbuf(m_str, wlen);
+    conv.ToWChar(wbuf, wlen, m_buf);
+}
+
+wxUTF8StringBufferLength::~wxUTF8StringBufferLength()
+{
+    wxCHECK_RET(m_lenSet, "length not set");
+
+    wxMBConvStrictUTF8 conv;
+    size_t wlen = conv.ToWChar(NULL, 0, m_buf, m_len);
+    wxCHECK_RET( wlen != wxCONV_FAILED, "invalid UTF-8 data in string buffer?" );
+
+    wxStringInternalBufferLength wbuf(m_str, wlen);
+    conv.ToWChar(wbuf, wlen, m_buf, m_len);
+    wbuf.SetLength(wlen);
+}
+#endif // wxUSE_UNICODE_WCHAR