added wxString::EndsWith() (patch 1483049)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39069 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -72,6 +72,7 @@ All:
|
|||||||
- Fixed bug where wxDateTime::Now() would sometimes return an incorrect value
|
- Fixed bug where wxDateTime::Now() would sometimes return an incorrect value
|
||||||
the first time it was called.
|
the first time it was called.
|
||||||
- Added wxString::rbegin() and rend()
|
- Added wxString::rbegin() and rend()
|
||||||
|
- Added wxString::EndsWith()
|
||||||
|
|
||||||
|
|
||||||
All (GUI):
|
All (GUI):
|
||||||
|
@@ -124,7 +124,8 @@ length of the prefix then.
|
|||||||
\helpref{CmpNoCase}{wxstringcmpnocase}\\
|
\helpref{CmpNoCase}{wxstringcmpnocase}\\
|
||||||
\helpref{IsSameAs}{wxstringissameas}\\
|
\helpref{IsSameAs}{wxstringissameas}\\
|
||||||
\helpref{Matches}{wxstringmatches}\\
|
\helpref{Matches}{wxstringmatches}\\
|
||||||
\helpref{StartsWith}{wxstringstartswith}
|
\helpref{StartsWith}{wxstringstartswith}\\
|
||||||
|
\helpref{EndsWith}{wxstringendswith}
|
||||||
|
|
||||||
\membersection{Substring extraction}\label{substringextractioninwxstring}
|
\membersection{Substring extraction}\label{substringextractioninwxstring}
|
||||||
|
|
||||||
@@ -140,7 +141,9 @@ substring.
|
|||||||
\helpref{BeforeLast}{wxstringbeforelast}\\
|
\helpref{BeforeLast}{wxstringbeforelast}\\
|
||||||
\helpref{AfterFirst}{wxstringafterfirst}\\
|
\helpref{AfterFirst}{wxstringafterfirst}\\
|
||||||
\helpref{AfterLast}{wxstringafterlast}\\
|
\helpref{AfterLast}{wxstringafterlast}\\
|
||||||
\helpref{StartsWith}{wxstringstartswith}
|
\helpref{StartsWith}{wxstringstartswith}\\
|
||||||
|
\helpref{EndsWith}{wxstringendswith}
|
||||||
|
|
||||||
|
|
||||||
\membersection{Case conversion}\label{caseconversioninwxstring}
|
\membersection{Case conversion}\label{caseconversioninwxstring}
|
||||||
|
|
||||||
@@ -967,6 +970,16 @@ of the string (i.e. after the prefix) into {\it rest} string if it is not
|
|||||||
{\tt NULL}. Otherwise, the function returns {\tt false} and doesn't modify the
|
{\tt NULL}. Otherwise, the function returns {\tt false} and doesn't modify the
|
||||||
{\it rest}.
|
{\it rest}.
|
||||||
|
|
||||||
|
\membersection{wxString::EndsWith}\label{wxstringendswith}
|
||||||
|
|
||||||
|
\constfunc{bool}{EndsWith}{\param{const wxChar }{*suffix}, \param{wxString }{*rest = NULL}}
|
||||||
|
|
||||||
|
This function can be used to test if the string ends with the specified
|
||||||
|
{\it suffix}. If it does, the function will return {\tt true} and put the
|
||||||
|
beginning of the string before the suffix into {\it rest} string if it is not
|
||||||
|
{\tt NULL}. Otherwise, the function returns {\tt false} and doesn't
|
||||||
|
modify the {\it rest}.
|
||||||
|
|
||||||
\membersection{wxString::Strip}\label{wxstringstrip}
|
\membersection{wxString::Strip}\label{wxstringstrip}
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
|
@@ -1056,10 +1056,14 @@ public:
|
|||||||
wxString operator()(size_t start, size_t len) const
|
wxString operator()(size_t start, size_t len) const
|
||||||
{ return Mid(start, len); }
|
{ return Mid(start, len); }
|
||||||
|
|
||||||
// check that the string starts with prefix and return the rest of the
|
// check if the string starts with the given prefix and return the rest
|
||||||
// string in the provided pointer if it is not NULL, otherwise return
|
// of the string in the provided pointer if it is not NULL; otherwise
|
||||||
// false
|
// return false
|
||||||
bool StartsWith(const wxChar *prefix, wxString *rest = NULL) const;
|
bool StartsWith(const wxChar *prefix, wxString *rest = NULL) const;
|
||||||
|
// check if the string ends with the given suffix and return the
|
||||||
|
// beginning of the string before the suffix in the provided pointer if
|
||||||
|
// it is not NULL; otherwise return false
|
||||||
|
bool EndsWith(const wxChar *suffix, wxString *rest = NULL) const;
|
||||||
|
|
||||||
// get first nCount characters
|
// get first nCount characters
|
||||||
wxString Left(size_t nCount) const;
|
wxString Left(size_t nCount) const;
|
||||||
|
@@ -1394,6 +1394,27 @@ bool wxString::StartsWith(const wxChar *prefix, wxString *rest) const
|
|||||||
return true;
|
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
|
// extract nCount last (rightmost) characters
|
||||||
wxString wxString::Right(size_t nCount) const
|
wxString wxString::Right(size_t nCount) const
|
||||||
{
|
{
|
||||||
|
@@ -165,11 +165,10 @@ void StringTestCase::Extraction()
|
|||||||
|
|
||||||
wxString rest;
|
wxString rest;
|
||||||
|
|
||||||
#define TEST_STARTS_WITH( prefix , correct_rest, result ) \
|
#define TEST_STARTS_WITH(prefix, correct_rest, result) \
|
||||||
CPPUNIT_ASSERT( \
|
CPPUNIT_ASSERT_EQUAL(result, s.StartsWith(prefix, &rest)); \
|
||||||
( s.StartsWith( prefix, &rest ) == result ) && \
|
if ( result ) \
|
||||||
( ( result == false ) || ( wxStrcmp( correct_rest , rest ) == 0 ) ) \
|
CPPUNIT_ASSERT_EQUAL(wxString(correct_rest), rest)
|
||||||
)
|
|
||||||
|
|
||||||
TEST_STARTS_WITH( _T("Hello"), _T(", world!"), true );
|
TEST_STARTS_WITH( _T("Hello"), _T(", world!"), true );
|
||||||
TEST_STARTS_WITH( _T("Hello, "), _T("world!"), true );
|
TEST_STARTS_WITH( _T("Hello, "), _T("world!"), true );
|
||||||
@@ -180,6 +179,23 @@ void StringTestCase::Extraction()
|
|||||||
TEST_STARTS_WITH( _T("Hi"), _T(""), false );
|
TEST_STARTS_WITH( _T("Hi"), _T(""), false );
|
||||||
|
|
||||||
#undef TEST_STARTS_WITH
|
#undef TEST_STARTS_WITH
|
||||||
|
|
||||||
|
#define TEST_ENDS_WITH(suffix, correct_rest, result) \
|
||||||
|
CPPUNIT_ASSERT_EQUAL(result, s.EndsWith(suffix, &rest)); \
|
||||||
|
if ( result ) \
|
||||||
|
CPPUNIT_ASSERT_EQUAL(wxString(correct_rest), rest)
|
||||||
|
|
||||||
|
TEST_ENDS_WITH( _T(""), _T("Hello, world!"), true );
|
||||||
|
TEST_ENDS_WITH( _T("!"), _T("Hello, world"), true );
|
||||||
|
TEST_ENDS_WITH( _T(", world!"), _T("Hello"), true );
|
||||||
|
TEST_ENDS_WITH( _T("ello, world!"), _T("H"), true );
|
||||||
|
TEST_ENDS_WITH( _T("Hello, world!"), _T(""), true );
|
||||||
|
TEST_ENDS_WITH( _T("very long string"), _T(""), false );
|
||||||
|
TEST_ENDS_WITH( _T("?"), _T(""), false );
|
||||||
|
TEST_ENDS_WITH( _T("Hello, world"), _T(""), false );
|
||||||
|
TEST_ENDS_WITH( _T("Gello, world!"), _T(""), false );
|
||||||
|
|
||||||
|
#undef TEST_ENDS_WITH
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringTestCase::Find()
|
void StringTestCase::Find()
|
||||||
|
Reference in New Issue
Block a user