fix(string_util): Join vector of strings

This commit is contained in:
Michael Carlberg 2016-11-27 01:32:21 +01:00
parent 4852f2817c
commit 6f6c5b7459
2 changed files with 3 additions and 3 deletions

View File

@ -28,7 +28,7 @@ namespace string_util {
string ltrim(const string& haystack, char needle); string ltrim(const string& haystack, char needle);
string rtrim(const string& haystack, char needle); string rtrim(const string& haystack, char needle);
string trim(const string& haystack, char needle); string trim(const string& haystack, char needle);
string join(vector<string> strs, string delim); string join(const vector<string>& strs, const string& delim);
vector<string>& split_into(const string& s, char delim, vector<string>& container); vector<string>& split_into(const string& s, char delim, vector<string>& container);
vector<string> split(const string& s, char delim); vector<string> split(const string& s, char delim);
size_t find_nth(const string& haystack, size_t pos, const string& needle, size_t nth); size_t find_nth(const string& haystack, size_t pos, const string& needle, size_t nth);

View File

@ -164,10 +164,10 @@ namespace string_util {
/** /**
* Join all strings in vector into a single string separated by delim * Join all strings in vector into a single string separated by delim
*/ */
string join(vector<string> strs, string delim) { string join(const vector<string>& strs, const string& delim) {
string str; string str;
for (auto& s : strs) { for (auto& s : strs) {
str.append((str.empty() ? "" : move(delim)) + s); str += (str.empty() ? "" : delim) + s;
} }
return str; return str;
} }