utils: Pass by value where it makes sense

This commit is contained in:
Albert S. 2021-10-09 00:24:22 +02:00
rodzic b1a8572eb6
commit 92e7390056
2 zmienionych plików z 6 dodań i 6 usunięć

Wyświetl plik

@ -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();

Wyświetl plik

@ -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);