aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-11-10 14:59:03 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-12-01 13:45:43 +0100
commit88798613ee288c7a801dcc1e73723a10a385df38 (patch)
treeb0e6f1a435b7028de39d8d38b6a68b4c304ced60 /src/libutil
parentc0d1354b7da9ffc2923bc102abb67d03b655fbbf (diff)
replaceStrings(): Use std::string_view
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc6
-rw-r--r--src/libutil/util.hh2
2 files changed, 4 insertions, 4 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 01ab9111f..c1b12e725 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -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);
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index cafe93702..117fe86e7 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -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);