refactor: Pass by value

This commit is contained in:
Michael Carlberg
2016-06-21 03:59:43 +02:00
parent b26ab9ce5f
commit e1f8c001dd
72 changed files with 253 additions and 253 deletions

View File

@ -4,11 +4,11 @@
namespace string
{
bool compare(const std::string& s1, const std::string& s2) {
bool compare(std::string s1, std::string s2) {
return lower(s1) == lower(s2);
}
// std::string upper(const std::string& s)
// std::string upper(std::string s)
// {
// std::string str(s);
// for (auto &c : str)
@ -16,7 +16,7 @@ namespace string
// return str;
// }
std::string lower(const std::string& s)
std::string lower(std::string s)
{
std::string str(s);
for (auto &c : str)
@ -24,7 +24,7 @@ namespace string
return str;
}
std::string replace(const std::string& haystack, const std::string& needle, const std::string& replacement)
std::string replace(std::string haystack, std::string needle, std::string replacement)
{
std::string str(haystack);
std::string::size_type pos;
@ -33,15 +33,15 @@ namespace string
return str;
}
std::string replace_all(const std::string& haystack, const std::string& needle, const std::string& replacement) {
std::string replace_all(std::string haystack, std::string needle, std::string replacement) {
return boost::replace_all_copy(haystack, needle, replacement);
}
std::string squeeze(const std::string& haystack, const char &needle) {
std::string squeeze(std::string haystack, const char &needle) {
return replace_all(haystack, {needle, needle}, {needle});
}
// std::string strip(const std::string& haystack, const char &needle)
// std::string strip(std::string haystack, const char &needle)
// {
// std::string str(haystack);
// std::string::size_type pos;
@ -50,7 +50,7 @@ namespace string
// return str;
// }
std::string strip_trailing_newline(const std::string& haystack)
std::string strip_trailing_newline(std::string haystack)
{
std::string str(haystack);
if (str[str.length()-1] == '\n')
@ -58,11 +58,11 @@ namespace string
return str;
}
std::string trim(const std::string& haystack, const char &needle) {
std::string trim(std::string haystack, const char &needle) {
return rtrim(ltrim(haystack, needle), needle);
}
std::string ltrim(const std::string& haystack, const char &needle)
std::string ltrim(std::string haystack, const char &needle)
{
std::string str(haystack);
while (str[0] == needle)
@ -70,7 +70,7 @@ namespace string
return str;
}
std::string rtrim(const std::string& haystack, const char &needle)
std::string rtrim(std::string haystack, const char &needle)
{
std::string str(haystack);
while (str[str.length()-1] == needle)
@ -78,7 +78,7 @@ namespace string
return str;
}
std::string join(const std::vector<std::string> &strs, const std::string& delim)
std::string join(const std::vector<std::string> &strs, std::string delim)
{
std::string str;
for (auto &s : strs)
@ -86,13 +86,13 @@ namespace string
return str;
}
std::vector<std::string> split(const std::string& s, const char &delim)
std::vector<std::string> split(std::string s, const char &delim)
{
std::vector<std::string> vec;
return split_into(s, delim, vec);
}
std::vector<std::string> &split_into(const std::string& s, const char &delim, std::vector<std::string> &container)
std::vector<std::string> &split_into(std::string s, const char &delim, std::vector<std::string> &container)
{
std::string str;
std::stringstream buffer(s);
@ -101,7 +101,7 @@ namespace string
return container;
}
std::size_t find_nth(const std::string& haystack, std::size_t pos, const std::string& needle, std::size_t nth)
std::size_t find_nth(std::string haystack, std::size_t pos, std::string needle, std::size_t nth)
{
std::size_t found_pos = haystack.find(needle, pos);
if(0 == nth || std::string::npos == found_pos) return found_pos;