Moved string replace function from stream library to util library

Change-Id: Icea1eed11b241063af39d0c7cf23f1733f96012c
This commit is contained in:
Marco 2022-12-26 15:57:19 +01:00 committed by Thulinma
parent 877216efd0
commit 62b14d958d
3 changed files with 30 additions and 29 deletions

View file

@ -150,6 +150,16 @@ namespace Util{
}
}
/// Replaces any occurrences of 'from' with 'to' in 'str'.
void replace(std::string &str, const std::string &from, const std::string &to){
if (from.empty()){return;}
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != std::string::npos){
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
}
//Returns the time to wait in milliseconds for exponential back-off waiting.
//If currIter > maxIter, always returns 5ms to prevent tight eternal loops when mistakes are made
//Otherwise, exponentially increases wait time for a total of maxWait milliseconds after maxIter calls.