replaceStrings(): Use std::string_view
This commit is contained in:
parent
c0d1354b7d
commit
88798613ee
2 changed files with 4 additions and 4 deletions
|
@ -1273,11 +1273,11 @@ string trim(const string & s, const string & whitespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string replaceStrings(const std::string & s,
|
string replaceStrings(std::string_view s,
|
||||||
const std::string & from, const std::string & to)
|
const std::string & from, const std::string & to)
|
||||||
{
|
{
|
||||||
if (from.empty()) return s;
|
string res(s);
|
||||||
string res = s;
|
if (from.empty()) return res;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
while ((pos = res.find(from, pos)) != std::string::npos) {
|
while ((pos = res.find(from, pos)) != std::string::npos) {
|
||||||
res.replace(pos, from.size(), to);
|
res.replace(pos, from.size(), to);
|
||||||
|
|
|
@ -383,7 +383,7 @@ string trim(const string & s, const string & whitespace = " \n\r\t");
|
||||||
|
|
||||||
|
|
||||||
/* Replace all occurrences of a string inside another string. */
|
/* Replace all occurrences of a string inside another string. */
|
||||||
string replaceStrings(const std::string & s,
|
string replaceStrings(std::string_view s,
|
||||||
const std::string & from, const std::string & to);
|
const std::string & from, const std::string & to);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue