From: Vadim Zeitlin Date: Thu, 18 Jun 1998 13:20:42 +0000 (+0000) Subject: 1) Right(char ch) now returns the part of the string after the last X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/c8cfb486fbb0b901295ab19c4e0b31bc6526f7a3 1) Right(char ch) now returns the part of the string after the last occurence of ch _without_ ch itself (like Left(char ch)) 2) Added wxString::Scanf() and wxString::ScanfV() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@108 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/string.h b/include/wx/string.h index 0b413e841f..2b65099b97 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -349,12 +349,16 @@ public: //@} //@} - /** @name formated output */ + /** @name formated input/output */ //@{ /// as sprintf(), returns the number of characters written or < 0 on error int Printf(const char *pszFormat, ...); /// as vprintf(), returns the number of characters written or < 0 on error int PrintfV(const char* pszFormat, va_list argptr); + /// as sscanf() + int Scanf(const char *pszFormat, ...) const; + /// as vsscanf() + int ScanfV(const char *pszFormat, va_list argptr) const; //@} // get writable buffer of at least nLen characters diff --git a/src/common/string.cpp b/src/common/string.cpp index 92573c4d4b..10e64bad12 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -569,7 +569,7 @@ wxString wxString::Right(char ch) const if ( iPos == NOT_FOUND ) str = *this; else - str = c_str() + iPos; + str = c_str() + iPos + 1; return str; } @@ -837,7 +837,7 @@ int wxString::Find(const char *pszSub) const } // --------------------------------------------------------------------------- -// formatted output +// formatted input/output // --------------------------------------------------------------------------- int wxString::Printf(const char *pszFormat, ...) { @@ -853,7 +853,7 @@ int wxString::Printf(const char *pszFormat, ...) int wxString::PrintfV(const char* pszFormat, va_list argptr) { - static char s_szScratch[1024]; + static char s_szScratch[1024]; // @@@@ shouldn't use fixed-size buffer! int iLen = vsprintf(s_szScratch, pszFormat, argptr); AllocBeforeWrite(iLen); @@ -862,6 +862,23 @@ int wxString::PrintfV(const char* pszFormat, va_list argptr) return iLen; } +int wxString::Scanf(const char *pszFormat, ...) const +{ + va_list argptr; + va_start(argptr, pszFormat); + + int iLen = ScanfV(pszFormat, argptr); + + va_end(argptr); + + return iLen; +} + +int wxString::ScanfV(const char *pszFormat, va_list argptr) const +{ + return vsscanf(c_str(), pszFormat, argptr); +} + // --------------------------------------------------------------------------- // standard C++ library string functions // ---------------------------------------------------------------------------