]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
Removed references to separate prop and porting docs. Added imagtiff.cpp
[wxWidgets.git] / src / common / string.cpp
index ed777353a7e37d8cc35e9183dc453a3f34b63b16..da23dda0f4862e0c0769879fa8e78c1aac0cb1a5 100644 (file)
@@ -107,7 +107,7 @@ extern const wxChar WXDLLEXPORT *wxEmptyString = &g_strEmpty.dummy;
 //       function wxVsnprintfA (A for ANSI), should also find one for Unicode
 //       strings in Unicode build
 #ifdef __WXMSW__
-    #if defined(__VISUALC__) || defined(wxUSE_NORLANDER_HEADERS)
+    #if (defined(__VISUALC__) || defined(wxUSE_NORLANDER_HEADERS)) && !defined(__MINGW32__)
         #define wxVsnprintfA     _vsnprintf
     #endif
 #else   // !Windows
@@ -1028,6 +1028,49 @@ int wxString::Find(const wxChar *pszSub) const
   return (psz == NULL) ? wxNOT_FOUND : psz - (const wxChar*) m_pchData;
 }
 
+// ----------------------------------------------------------------------------
+// conversion to numbers
+// ----------------------------------------------------------------------------
+
+bool wxString::ToLong(long *val) const
+{
+    wxCHECK_MSG( val, FALSE, _T("NULL pointer in wxString::ToLong") );
+
+    const wxChar *start = c_str();
+    wxChar *end;
+    *val = wxStrtol(start, &end, 10);
+
+    // return TRUE only if scan was stopped by the terminating NUL and if the
+    // string was not empty to start with
+    return !*end && (end != start);
+}
+
+bool wxString::ToULong(unsigned long *val) const
+{
+    wxCHECK_MSG( val, FALSE, _T("NULL pointer in wxString::ToULong") );
+
+    const wxChar *start = c_str();
+    wxChar *end;
+    *val = wxStrtoul(start, &end, 10);
+
+    // return TRUE only if scan was stopped by the terminating NUL and if the
+    // string was not empty to start with
+    return !*end && (end != start);
+}
+
+bool wxString::ToDouble(double *val) const
+{
+    wxCHECK_MSG( val, FALSE, _T("NULL pointer in wxString::ToDouble") );
+
+    const wxChar *start = c_str();
+    wxChar *end;
+    *val = wxStrtod(start, &end);
+
+    // return TRUE only if scan was stopped by the terminating NUL and if the
+    // string was not empty to start with
+    return !*end && (end != start);
+}
+
 // ---------------------------------------------------------------------------
 // stream-like operators
 // ---------------------------------------------------------------------------
@@ -1059,6 +1102,28 @@ wxString& wxString::operator<<(double d)
 // formatted output
 // ---------------------------------------------------------------------------
 
+/* static */
+wxString wxString::Format(const wxChar *pszFormat, ...)
+{
+    va_list argptr;
+    va_start(argptr, pszFormat);
+
+    wxString s;
+    s.PrintfV(pszFormat, argptr);
+
+    va_end(argptr);
+
+    return s;
+}
+
+/* static */
+wxString wxString::FormatV(const wxChar *pszFormat, va_list argptr)
+{
+    wxString s;
+    s.Printf(pszFormat, argptr);
+    return s;
+}
+
 int wxString::Printf(const wxChar *pszFormat, ...)
 {
   va_list argptr;
@@ -1737,20 +1802,8 @@ void wxArrayString::Copy(const wxArrayString& src)
   if ( src.m_nCount > ARRAY_DEFAULT_INITIAL_SIZE )
     Alloc(src.m_nCount);
 
-  // we can't just copy the pointers here because otherwise we would share
-  // the strings with another array because strings are ref counted
-#if 0
-  if ( m_nCount != 0 )
-    memcpy(m_pItems, src.m_pItems, m_nCount*sizeof(wxChar *));
-#endif // 0
-
   for ( size_t n = 0; n < src.m_nCount; n++ )
     Add(src[n]);
-
-  // if the other array is auto sorted too, we're already sorted, but
-  // otherwise we should rearrange the items
-  if ( m_autoSort && !src.m_autoSort )
-    Sort();
 }
 
 // grow the array