diff --git a/uppsrc/Core/AString.hpp b/uppsrc/Core/AString.hpp index 8161f78f0..dd03d5d06 100644 --- a/uppsrc/Core/AString.hpp +++ b/uppsrc/Core/AString.hpp @@ -60,6 +60,29 @@ int AString::ReverseFind(int chr, int from) const return -1; } +template +int AString::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 +int AString::ReverseFind(const tchar *s, int from) const +{ + return ReverseFind(strlen__(s), s, from); +} + template int AString::ReverseFind(int chr) const { diff --git a/uppsrc/Core/String.h b/uppsrc/Core/String.h index ff8b4b4aa..4918e4a0e 100644 --- a/uppsrc/Core/String.h +++ b/uppsrc/Core/String.h @@ -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()); }