utils: Pass by value where it makes sense

This commit is contained in:
Albert S. 2021-10-09 00:24:22 +02:00
parent b1a8572eb6
commit 92e7390056
2 changed files with 6 additions and 6 deletions

View File

@ -84,7 +84,7 @@ std::string utils::urldecode(std::string_view str)
return result;
}
std::vector<std::string> utils::split(const std::string &str, char delim)
std::vector<std::string> utils::split(std::string str, char delim)
{
std::vector<std::string> result;
std::stringstream stream(str);
@ -97,7 +97,7 @@ std::vector<std::string> utils::split(const std::string &str, char delim)
}
// TODO: can easily break if we pass a regex here
std::vector<std::string> utils::split(const std::string &str, const std::string &delim)
std::vector<std::string> utils::split(std::string str, const std::string &delim)
{
std::regex regex{delim + "+"};
return split(str, regex);
@ -112,7 +112,7 @@ std::vector<std::string> utils::split(const std::string &str, std::regex &regex)
return result;
}
std::string utils::strreplace(const std::string &str, const std::string &search, const std::string &replace)
std::string utils::strreplace(std::string str, const std::string &search, const std::string &replace)
{
std::string result = str;
auto searchlength = search.length();

View File

@ -11,11 +11,11 @@
namespace utils
{
std::vector<std::string> split(const std::string &str, char delim);
std::vector<std::string> split(const std::string &str, const std::string &delim);
std::vector<std::string> split(std::string str, char delim);
std::vector<std::string> split(std::string str, const std::string &delim);
std::vector<std::string> split(const std::string &str, std::regex &regex);
std::string urldecode(std::string_view str);
std::string strreplace(const std::string &str, const std::string &search, const std::string &replace);
std::string strreplace(std::string str, const std::string &search, const std::string &replace);
std::string html_xss(std::string_view str);
std::string getenv(const std::string &key);