string: Added const replace and replaceAll

which return the replaced string rather than modify the string the function is
called for.
This commit is contained in:
Henry Weller
2021-10-25 10:15:44 +01:00
parent ad28cb49b5
commit cd80831261
3 changed files with 45 additions and 5 deletions

View File

@ -78,6 +78,17 @@ Foam::string& Foam::string::replace
}
Foam::string Foam::string::replace
(
const string& oldStr,
const string& newStr,
size_type start
) const
{
return string(*this).replace(oldStr, newStr, start);
}
Foam::string& Foam::string::replaceAll
(
const string& oldStr,
@ -100,6 +111,17 @@ Foam::string& Foam::string::replaceAll
}
Foam::string Foam::string::replaceAll
(
const string& oldStr,
const string& newStr,
size_type start
) const
{
return string(*this).replaceAll(oldStr, newStr, start);
}
Foam::string& Foam::string::expand(const bool allowEmpty)
{
stringOps::inplaceExpand(*this, allowEmpty);

View File

@ -165,9 +165,27 @@ public:
//- Avoid masking the normal std::string replace
using std::string::replace;
//- In this string replace first occurrence of sub-string oldStr
// with newStr starting at start
string& replace
(
const string& oldStr,
const string& newStr,
size_type start = 0
);
//- Replace first occurrence of sub-string oldStr with newStr
// starting at start
string& replace
string replace
(
const string& oldStr,
const string& newStr,
size_type start = 0
) const;
//- In this string replace all occurrences of sub-string oldStr
// with newStr starting at start
string& replaceAll
(
const string& oldStr,
const string& newStr,
@ -176,12 +194,12 @@ public:
//- Replace all occurrences of sub-string oldStr with newStr
// starting at start
string& replaceAll
string replaceAll
(
const string& oldStr,
const string& newStr,
size_type start = 0
);
) const;
//- Expand initial tildes and all occurrences of environment variables
// Expansion includes: