mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-08 02:54:56 -06:00
Core: [W]String::ReverseFind
git-svn-id: svn://ultimatepp.org/upp/trunk@2453 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
5de2ea2e3a
commit
296e44e509
2 changed files with 28 additions and 1 deletions
|
|
@ -60,6 +60,29 @@ int AString<B>::ReverseFind(int chr, int from) const
|
|||
return -1;
|
||||
}
|
||||
|
||||
template <class B>
|
||||
int AString<B>::ReverseFind(int len, const tchar *s, int from) const
|
||||
{
|
||||
ASSERT(from >= 0 && from <= GetLength());
|
||||
if(from < GetLength()) {
|
||||
const tchar *ptr = B::Begin();
|
||||
const tchar *p = ptr + from - len + 1;
|
||||
len *= sizeof(tchar);
|
||||
while(p >= ptr) {
|
||||
if(memcmp(s, p, len) == 0)
|
||||
return (int)(p - ptr);
|
||||
p--;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
template <class B>
|
||||
int AString<B>::ReverseFind(const tchar *s, int from) const
|
||||
{
|
||||
return ReverseFind(strlen__(s), s, from);
|
||||
}
|
||||
|
||||
template <class B>
|
||||
int AString<B>::ReverseFind(int chr) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -87,7 +87,11 @@ public:
|
|||
int Find(int len, const tchar *s, int from) const;
|
||||
int Find(const tchar *s, int from = 0) const;
|
||||
int Find(const String& s, int from = 0) const { return Find(s.GetCount(), ~s, from); }
|
||||
|
||||
|
||||
int ReverseFind(int len, const tchar *s, int from) const;
|
||||
int ReverseFind(const tchar *s, int from = 0) const;
|
||||
int ReverseFind(const String& s, int from = 0) const { return ReverseFind(s.GetCount(), ~s, from); }
|
||||
|
||||
bool StartsWith(const tchar *s, int len) const;
|
||||
bool StartsWith(const tchar *s) const { return StartsWith(s, strlen__(s)); }
|
||||
bool StartsWith(const String& s) const { return StartsWith(~s, s.GetLength()); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue