Originally Posted by
laserlight
Actually, I am a little confused because you were talking about Find, but now you are talking about Replace
Uhh ya, looking back, I can see why...
Find had the const or not const iterator problem.
Replace was broken out and have the private interface problem.
If that is the situation, then Replace should be a member function.
I mean, currently it looks like:
Code:
template<typename StrType> void Replace(const StrType& strSrc,
const StrType& strReplaceWhat, const StrType& strReplaceWith)
{
Replace(strSrc, strReplaceWhat, strReplaceWith,
strReplaceWhat.begin(), strReplaceWhat.end());
}
//template<typename StrType, typename ItType> void Replace(const
StrType& strReplaceWhat, const StrType& strReplaceWith, const ItType& vStart);
template<typename StrType, typename ItType> void Replace(const StrType& strSrc,
const StrType& strReplaceWhat, const StrType& strReplaceWith, const ItType& vStart,
const ItType& vEnd)
{
int32_t nNeededSize = ReplaceInternal(strSrc, strReplaceWhat, strReplaceWith, false,
vStart, vEnd);
if (nNeededSize > 0) strSrc.resize(nNeededSize); //PrepareBuffer(nNeededSize);
ReplaceInternal(strSrc, strReplaceWhat, strReplaceWith, true, vStart, vEnd);
}
template<typename StrType, typename ItType> int32_t ReplaceInternal(const StrType& strSrc,
const StrType& strReplaceWhat, const StrType& strReplaceWith, bool bReplace,
const ItType& vStart, const ItType& vEnd)
Replace is the public interface of the free function that you should call to do the work.
Then they will wrap ReplaceInternal that will do the actual replacing.
But ReplaceInternal shouldn't be called directly because 1) it takes a bool that should not be passed directly and 2) it has only one version - the one that takes a range. Therefore ReplaceInternal should be hidden away from prying eyes, but since it's free it cannot.
But making it a member will destroy the essence of generic functions...
Unless ReplaceInternal can wrap other generic functions to do its work. Perhaps that might be a good idea? Then ReplaceInternal could be made a member.