mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-28 06:12:53 -06:00
Core: String::Replace
git-svn-id: svn://ultimatepp.org/upp/trunk@2765 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
51c2b14b7e
commit
54df285bf3
2 changed files with 22 additions and 0 deletions
|
|
@ -77,6 +77,24 @@ int AString<B>::ReverseFind(int len, const tchar *s, int from) const
|
|||
return -1;
|
||||
}
|
||||
|
||||
template <class B>
|
||||
void AString<B>::Replace(const tchar *find, int findlen, const tchar *replace, int replacelen)
|
||||
{
|
||||
String r;
|
||||
int i = 0;
|
||||
const tchar *p = Begin();
|
||||
for(;;) {
|
||||
int j = Find(findlen, find, i);
|
||||
if(j < 0)
|
||||
break;
|
||||
r.Cat(p + i, j - i);
|
||||
r.Cat(replace, replacelen);
|
||||
i = j + findlen;
|
||||
}
|
||||
r.Cat(p + i, GetCount() - i);
|
||||
*this = r;
|
||||
}
|
||||
|
||||
template <class B>
|
||||
int AString<B>::ReverseFind(const tchar *s, int from) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -94,6 +94,10 @@ public:
|
|||
int ReverseFind(const tchar *s) const { return ReverseFind(s, GetLength()-1);}
|
||||
int ReverseFind(const String& s) const { return ReverseFind(s, GetLength()-1);}
|
||||
|
||||
void Replace(const tchar *find, int findlen, const tchar *replace, int replacelen);
|
||||
void Replace(const String& find, const String& replace) { Replace(~find, find.GetCount(), ~replace, replace.GetCount()); }
|
||||
void Replace(const tchar *find, const tchar *replace) { Replace(find, strlen(find), replace, strlen(replace)); }
|
||||
|
||||
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