From 8e52d497bd8861007bed8a4cef58ebe1a1a79f15 Mon Sep 17 00:00:00 2001 From: prozacx Date: Fri, 6 Jan 2006 18:53:09 +0000 Subject: [PATCH] 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 --- String.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/String.cpp b/String.cpp index 00e934e3..c2f493e6 100644 --- a/String.cpp +++ b/String.cpp @@ -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++; }