// 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
// vsnprintf() will not terminate the string with '\0' if there is not
// enough place, but we want the string to always be NUL terminated
int rc = wxVsnprintfA(buf, len - 1, format, argptr);
- buf[len] = 0;
+ if ( rc == -1 )
+ {
+ buf[len] = 0;
+ }
return rc;
#endif // Unicode/ANSI
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
// ---------------------------------------------------------------------------
// formatted output
// ---------------------------------------------------------------------------
+/* static */
+wxString wxString::Format(const wxChar *pszFormat, ...)
+{
+ va_list argptr;
+ va_start(argptr, pszFormat);
+
+ wxString s = FormatV(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;
return npos;
}
-wxString wxString::substr(size_t nStart, size_t nLen) const
-{
- // npos means 'take all'
- if ( nLen == npos )
- nLen = 0;
-
- wxASSERT( nStart + nLen <= Len() );
-
- return wxString(c_str() + nStart, nLen == npos ? 0 : nLen);
-}
-
wxString& wxString::erase(size_t nStart, size_t nLen)
{
wxString strTmp(c_str(), nStart);