find_first/last_[not]_of() functions added
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2482 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
adde8c9807
commit
969d318c6a
@ -836,32 +836,37 @@ public:
|
||||
|
||||
// find first/last occurence of any character in the set
|
||||
|
||||
//
|
||||
size_t find_first_of(const wxString& str, size_t nStart = 0) const;
|
||||
//
|
||||
// as strpbrk() but starts at nStart, returns npos if not found
|
||||
size_t find_first_of(const wxString& str, size_t nStart = 0) const
|
||||
{ return find_first_of(str.c_str(), nStart); }
|
||||
// same as above
|
||||
size_t find_first_of(const wxChar* sz, size_t nStart = 0) const;
|
||||
// same as find(char, size_t)
|
||||
size_t find_first_of(wxChar c, size_t nStart = 0) const;
|
||||
//
|
||||
size_t find_last_of (const wxString& str, size_t nStart = npos) const;
|
||||
//
|
||||
size_t find_last_of (const wxChar* s, size_t nStart = npos) const;
|
||||
// same as rfind(char, size_t)
|
||||
size_t find_last_of (wxChar c, size_t nStart = npos) const;
|
||||
size_t find_first_of(wxChar c, size_t nStart = 0) const
|
||||
{ return find(c, nStart); }
|
||||
// find the last (starting from nStart) char from str in this string
|
||||
size_t find_last_of (const wxString& str, size_t nStart = npos) const
|
||||
{ return find_last_of(str.c_str(), nStart); }
|
||||
// same as above
|
||||
size_t find_last_of (const wxChar* sz, size_t nStart = npos) const;
|
||||
// same as above
|
||||
size_t find_last_of(wxChar c, size_t nStart = npos) const
|
||||
{ return rfind(c, nStart); }
|
||||
|
||||
// find first/last occurence of any character not in the set
|
||||
|
||||
//
|
||||
size_t find_first_not_of(const wxString& str, size_t nStart = 0) const;
|
||||
//
|
||||
size_t find_first_not_of(const wxChar* s, size_t nStart = 0) const;
|
||||
//
|
||||
// as strspn() (starting from nStart), returns npos on failure
|
||||
size_t find_first_not_of(const wxString& str, size_t nStart = 0) const
|
||||
{ return find_first_not_of(str.c_str(), nStart); }
|
||||
// same as above
|
||||
size_t find_first_not_of(const wxChar* sz, size_t nStart = 0) const;
|
||||
// same as above
|
||||
size_t find_first_not_of(wxChar ch, size_t nStart = 0) const;
|
||||
//
|
||||
// as strcspn()
|
||||
size_t find_last_not_of(const wxString& str, size_t nStart=npos) const;
|
||||
//
|
||||
size_t find_last_not_of(const wxChar* s, size_t nStart = npos) const;
|
||||
//
|
||||
// same as above
|
||||
size_t find_last_not_of(const wxChar* sz, size_t nStart = npos) const;
|
||||
// same as above
|
||||
size_t find_last_not_of(wxChar ch, size_t nStart = npos) const;
|
||||
|
||||
// All compare functions return -1, 0 or 1 if the [sub]string is less,
|
||||
|
@ -1410,7 +1410,7 @@ size_t wxString::rfind(const wxString& str, size_t nStart) const
|
||||
wxASSERT( str.GetStringData()->IsValid() );
|
||||
wxASSERT( nStart <= Len() );
|
||||
|
||||
// # could be quicker than that
|
||||
// TODO could be made much quicker than that
|
||||
const wxChar *p = c_str() + (nStart == npos ? Len() : nStart);
|
||||
while ( p >= c_str() + str.Len() ) {
|
||||
if ( wxStrncmp(p - str.Len(), str, str.Len()) == 0 )
|
||||
@ -1425,19 +1425,131 @@ size_t wxString::rfind(const wxString& str, size_t nStart) const
|
||||
#if !defined(__VISUALC__) || defined(__WIN32__)
|
||||
size_t wxString::rfind(const wxChar* sz, size_t nStart, size_t n) const
|
||||
{
|
||||
return rfind(wxString(sz, n == npos ? 0 : n), nStart);
|
||||
return rfind(wxString(sz, n == npos ? 0 : n), nStart);
|
||||
}
|
||||
|
||||
size_t wxString::rfind(wxChar ch, size_t nStart) const
|
||||
{
|
||||
wxASSERT( nStart <= Len() );
|
||||
if ( nStart == npos )
|
||||
{
|
||||
nStart = Len();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxASSERT( nStart <= Len() );
|
||||
}
|
||||
|
||||
const wxChar *p = wxStrrchr(c_str() + nStart, ch);
|
||||
const wxChar *p = wxStrrchr(c_str(), ch);
|
||||
|
||||
return p == NULL ? npos : p - c_str();
|
||||
if ( p == NULL )
|
||||
return npos;
|
||||
|
||||
size_t result = p - c_str();
|
||||
return ( result > nStart ) ? npos : result;
|
||||
}
|
||||
#endif // VC++ 1.5
|
||||
|
||||
size_t wxString::find_first_of(const wxChar* sz, size_t nStart) const
|
||||
{
|
||||
const char *start = c_str() + nStart;
|
||||
char *firstOf = strpbrk(start, sz);
|
||||
if ( firstOf )
|
||||
return firstOf - start;
|
||||
else
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t wxString::find_last_of(const wxChar* sz, size_t nStart) const
|
||||
{
|
||||
if ( nStart == npos )
|
||||
{
|
||||
nStart = Len();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxASSERT( nStart <= Len() );
|
||||
}
|
||||
|
||||
for ( const char *p = c_str() + length() - 1; p >= c_str(); p-- )
|
||||
{
|
||||
if ( wxStrchr(sz, *p) )
|
||||
return p - c_str();
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t wxString::find_first_not_of(const wxChar* sz, size_t nStart) const
|
||||
{
|
||||
if ( nStart == npos )
|
||||
{
|
||||
nStart = Len();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxASSERT( nStart <= Len() );
|
||||
}
|
||||
|
||||
size_t nAccept = strspn(c_str() + nStart, sz);
|
||||
if ( nAccept >= length() - nStart )
|
||||
return npos;
|
||||
else
|
||||
return nAccept;
|
||||
}
|
||||
|
||||
size_t wxString::find_first_not_of(wxChar ch, size_t nStart) const
|
||||
{
|
||||
wxASSERT( nStart <= Len() );
|
||||
|
||||
for ( const char *p = c_str() + nStart; *p; p++ )
|
||||
{
|
||||
if ( *p != ch )
|
||||
return p - c_str();
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t wxString::find_last_not_of(const wxChar* sz, size_t nStart) const
|
||||
{
|
||||
if ( nStart == npos )
|
||||
{
|
||||
nStart = Len();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxASSERT( nStart <= Len() );
|
||||
}
|
||||
|
||||
for ( const char *p = c_str() + nStart - 1; p >= c_str(); p-- )
|
||||
{
|
||||
if ( !wxStrchr(sz, *p) )
|
||||
return p - c_str();
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t wxString::find_last_not_of(wxChar ch, size_t nStart) const
|
||||
{
|
||||
if ( nStart == npos )
|
||||
{
|
||||
nStart = Len();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxASSERT( nStart <= Len() );
|
||||
}
|
||||
|
||||
for ( const char *p = c_str() + nStart - 1; p >= c_str(); p-- )
|
||||
{
|
||||
if ( *p != ch )
|
||||
return p - c_str();
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
wxString wxString::substr(size_t nStart, size_t nLen) const
|
||||
{
|
||||
// npos means 'take all'
|
||||
|
Loading…
Reference in New Issue
Block a user