replaceStrings(): Use std::string_view

This commit is contained in:
Eelco Dolstra 2020-11-10 14:59:03 +01:00
parent c0d1354b7d
commit 88798613ee
2 changed files with 4 additions and 4 deletions

View file

@ -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)
{
if (from.empty()) return s;
string res = s;
string res(s);
if (from.empty()) return res;
size_t pos = 0;
while ((pos = res.find(from, pos)) != std::string::npos) {
res.replace(pos, from.size(), to);

View file

@ -383,7 +383,7 @@ string trim(const string & s, const string & whitespace = " \n\r\t");
/* 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);