Fixed replace(inPlace) function

and added tests (should have done that in the first place - I'll never learn!)
This commit is contained in:
Phil Nash 2014-12-19 18:16:19 +00:00
parent db0421e840
commit 458b3ae257
4 changed files with 50 additions and 15 deletions

View file

@ -36,7 +36,21 @@ namespace Catch {
return start != std::string::npos ? str.substr( start, 1+end-start ) : "";
}
bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
bool replaced = false;
std::size_t i = str.find( replaceThis );
while( i != std::string::npos ) {
replaced = true;
str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() );
if( i < str.size()-withThis.size() )
i = str.find( replaceThis, i+withThis.size() );
else
i = std::string::npos;
}
return replaced;
}
pluralise::pluralise( std::size_t count, std::string const& label )
: m_count( count ),
m_label( label )