mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-31 17:07:52 +00:00
Fixed replace(inPlace) function
and added tests (should have done that in the first place - I'll never learn!)
This commit is contained in:
parent
db0421e840
commit
458b3ae257
4 changed files with 50 additions and 15 deletions
|
@ -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 )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue