Moved string replace function from stream library to util library
Change-Id: Icea1eed11b241063af39d0c7cf23f1733f96012c
This commit is contained in:
parent
877216efd0
commit
62b14d958d
3 changed files with 30 additions and 29 deletions
10
lib/util.cpp
10
lib/util.cpp
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue