utils: Pass by value where it makes sense
This commit is contained in:
parent
b1a8572eb6
commit
92e7390056
@ -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 ®ex)
|
||||
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();
|
||||
|
6
utils.h
6
utils.h
@ -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 ®ex);
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user