X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/eec47cc6c45a2d9a474cae9da897ebfdb0b7be21..00dff4d222ab3525d04c819142d44159b9b52f01:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 4e128a124f..04969d3246 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: string.cpp +// Name: src/common/string.cpp // Purpose: wxString class // Author: Vadim Zeitlin, Ryan Norton // Modified by: @@ -25,14 +25,13 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ - #pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP - #include "wx/defs.h" - #include "wx/string.h" - #include "wx/intl.h" - #include "wx/thread.h" + #include "wx/string.h" + #include "wx/intl.h" + #include "wx/thread.h" #endif #include @@ -40,7 +39,7 @@ #include #ifdef __SALFORDC__ - #include + #include #endif // allocating extra space for each string consumes more memory but speeds up @@ -1006,20 +1005,14 @@ int STRINGCLASS::compare(size_t nStart, size_t nLen, #if wxUSE_UNICODE // from multibyte string -wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength) +wxString::wxString(const char *psz, const wxMBConv& conv, size_t nLength) { // anything to do? if ( psz && nLength != 0 ) { if ( nLength == npos ) { - nLength = (size_t)-1; - } - else if ( nLength == length() ) - { - // this is important to avoid copying the string in cMB2WC: we're - // already NUL-terminated so we can pass this NUL with the data - nLength++; + nLength = wxNO_LEN; } size_t nLenWide; @@ -1031,7 +1024,7 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength) } //Convert wxString in Unicode mode to a multi-byte string -const wxCharBuffer wxString::mb_str(wxMBConv& conv) const +const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const { return conv.cWC2MB(c_str(), length() + 1 /* size, not length */, NULL); } @@ -1041,20 +1034,14 @@ const wxCharBuffer wxString::mb_str(wxMBConv& conv) const #if wxUSE_WCHAR_T // from wide string -wxString::wxString(const wchar_t *pwz, wxMBConv& conv, size_t nLength) +wxString::wxString(const wchar_t *pwz, const wxMBConv& conv, size_t nLength) { // anything to do? if ( pwz && nLength != 0 ) { if ( nLength == npos ) { - nLength = (size_t)-1; - } - else if ( nLength == length() ) - { - // this is important to avoid copying the string in cMB2WC: we're - // already NUL-terminated so we can pass this NUL with the data - nLength++; + nLength = wxNO_LEN; } size_t nLenMB; @@ -1067,7 +1054,7 @@ wxString::wxString(const wchar_t *pwz, wxMBConv& conv, size_t nLength) //Converts this string to a wide character string if unicode //mode is not enabled and wxUSE_WCHAR_T is enabled -const wxWCharBuffer wxString::wc_str(wxMBConv& conv) const +const wxWCharBuffer wxString::wc_str(const wxMBConv& conv) const { return conv.cMB2WC(c_str(), length() + 1 /* size, not length */, NULL); } @@ -1407,6 +1394,27 @@ bool wxString::StartsWith(const wxChar *prefix, wxString *rest) const return true; } + +// check that the string ends with suffix and return the rest of it in the +// provided pointer if it is not NULL, otherwise return false +bool wxString::EndsWith(const wxChar *suffix, wxString *rest) const +{ + wxASSERT_MSG( suffix, _T("invalid parameter in wxString::EndssWith") ); + + int start = length() - wxStrlen(suffix); + if ( start < 0 || wxStrcmp(c_str() + start, suffix) != 0 ) + return false; + + if ( rest ) + { + // put the rest of the string into provided pointer + rest->assign(*this, 0, start); + } + + return true; +} + + // extract nCount last (rightmost) characters wxString wxString::Right(size_t nCount) const {