Added Replace_n() and fixed internal loop bug in Replace() (thanks psycho for finding it)

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@595 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2006-01-06 18:53:09 +00:00
parent 91e78dda94
commit 8e52d497bd

View File

@@ -366,13 +366,19 @@ unsigned int CString::Replace(const CString& sReplace, const CString& sWith) {
return CString::Replace(*this, sReplace, sWith);
}
CString CString::Replace_n(const CString& sReplace, const CString& sWith) const {
CString sRet(*this);
sRet.Replace(sReplace, sWith);
return sRet;
}
unsigned int CString::Replace(CString& sStr, const CString& sReplace, const CString& sWith) {
unsigned int uRet = 0;
size_type uPos = sStr.find(sReplace);
while (uPos != npos) {
sStr.replace(uPos, sReplace.length(), sWith);
uPos = sStr.find(sReplace);
uPos = sStr.find(sReplace, uPos + sReplace.length() +1);
uRet++;
}