X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b568d04ffa191f9e3b643ca33526094eca0ba304..341e7d28891d72b0f7aee27ca41d5827d261c67b:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 280e105f25..764d0a41c6 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -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 @@ -203,7 +203,10 @@ extern int WXDLLEXPORT wxVsnprintf(wxChar *buf, size_t len, // 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 @@ -1025,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 // --------------------------------------------------------------------------- @@ -1056,6 +1102,27 @@ wxString& wxString::operator<<(double d) // 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; @@ -1640,17 +1707,6 @@ size_t wxString::find_last_not_of(wxChar ch, size_t nStart) const 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);