Core: [W]String::ReverseFind

git-svn-id: svn://ultimatepp.org/upp/trunk@2453 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2010-06-03 17:21:30 +00:00
parent 5de2ea2e3a
commit 296e44e509
2 changed files with 28 additions and 1 deletions

View file

@ -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
{

View file

@ -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()); }