From e36cf8518ab0a1f27e24ce75ced5b3b7ffe6432e Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 21 Jun 2016 06:01:21 +0200 Subject: [PATCH] refactor: Pass by value --- include/utils/string.hpp | 16 ++++++++-------- src/utils/string.cpp | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/utils/string.hpp b/include/utils/string.hpp index abcceb9f..4b1e5737 100644 --- a/include/utils/string.hpp +++ b/include/utils/string.hpp @@ -13,19 +13,19 @@ namespace string std::string replace(std::string haystack, std::string needle, std::string replacement); std::string replace_all(std::string haystack, std::string needle, std::string replacement); - std::string squeeze(std::string haystack, const char &needle); + std::string squeeze(std::string haystack, char needle); - // std::string strip(std::string haystack, const char &needle); + // std::string strip(std::string haystack, char needle); std::string strip_trailing_newline(std::string s); - std::string trim(std::string haystack, const char &needle); - std::string ltrim(std::string haystack, const char &needle); - std::string rtrim(std::string haystack, const char &needle); + std::string trim(std::string haystack, char needle); + std::string ltrim(std::string haystack, char needle); + std::string rtrim(std::string haystack, char needle); - std::string join(const std::vector &strs, std::string delim); + std::string join(std::vector strs, std::string delim); - std::vector split(std::string s, const char &delim); - std::vector &split_into(std::string s, const char &delim, std::vector &elems); + std::vector split(std::string s, char delim); + std::vector &split_into(std::string s, char delim, std::vector &elems); std::size_t find_nth(std::string haystack, std::size_t pos, std::string needle, std::size_t nth); } diff --git a/src/utils/string.cpp b/src/utils/string.cpp index fce66eb9..aa7d9d02 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -37,11 +37,11 @@ namespace string return boost::replace_all_copy(haystack, needle, replacement); } - std::string squeeze(std::string haystack, const char &needle) { + std::string squeeze(std::string haystack, char needle) { return replace_all(haystack, {needle, needle}, {needle}); } - // std::string strip(std::string haystack, const char &needle) + // std::string strip(std::string haystack, char needle) // { // std::string str(haystack); // std::string::size_type pos; @@ -58,11 +58,11 @@ namespace string return str; } - std::string trim(std::string haystack, const char &needle) { + std::string trim(std::string haystack, char needle) { return rtrim(ltrim(haystack, needle), needle); } - std::string ltrim(std::string haystack, const char &needle) + std::string ltrim(std::string haystack, char needle) { std::string str(haystack); while (str[0] == needle) @@ -70,7 +70,7 @@ namespace string return str; } - std::string rtrim(std::string haystack, const char &needle) + std::string rtrim(std::string haystack, 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 &strs, std::string delim) + std::string join(std::vector strs, std::string delim) { std::string str; for (auto &s : strs) @@ -86,13 +86,13 @@ namespace string return str; } - std::vector split(std::string s, const char &delim) + std::vector split(std::string s, char delim) { std::vector vec; return split_into(s, delim, vec); } - std::vector &split_into(std::string s, const char &delim, std::vector &container) + std::vector &split_into(std::string s, char delim, std::vector &container) { std::string str; std::stringstream buffer(s);