Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4069)

Unified Diff: base/strings/string_util.h

Issue 2691193002: Added StringPiece overloads for base::JoinString. (Closed)
Patch Set: Document why we have an explicit initializer_list overload. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/strings/string_util.cc » ('j') | base/strings/string_util.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/strings/string_util.h
diff --git a/base/strings/string_util.h b/base/strings/string_util.h
index e5cce8fd97e56f93e0717250b2b4bb60851c4806..2916848a270b3b7d7dbe15afcbf805c491d5fe2f 100644
--- a/base/strings/string_util.h
+++ b/base/strings/string_util.h
@@ -429,11 +429,28 @@ BASE_EXPORT char16* WriteInto(string16* str, size_t length_with_null);
BASE_EXPORT wchar_t* WriteInto(std::wstring* str, size_t length_with_null);
#endif
-// Does the opposite of SplitString().
+// Does the opposite of SplitString()/SplitStringPiece(). Joins a vector or list
+// of strings into a single string, inserting |separator| (which may be empty)
+// in between all elements.
+//
+// Prefer the StringPiece variant if possible, to avoid unnecessary copying.
BASE_EXPORT std::string JoinString(const std::vector<std::string>& parts,
StringPiece separator);
BASE_EXPORT string16 JoinString(const std::vector<string16>& parts,
StringPiece16 separator);
+BASE_EXPORT std::string JoinString(const std::vector<StringPiece>& parts,
+ StringPiece separator);
+BASE_EXPORT string16 JoinString(const std::vector<StringPiece16>& parts,
+ StringPiece16 separator);
+// Explicit initializer_list overloads are required to break ambiguity when used
+// with a literal initializer list (otherwise the compiler would not be able to
+// decide between the two other overloads).
+BASE_EXPORT std::string JoinString(
+ const std::initializer_list<StringPiece>& parts,
+ StringPiece separator);
+BASE_EXPORT string16
+JoinString(const std::initializer_list<StringPiece16>& parts,
+ StringPiece16 separator);
// Replace $1-$2-$3..$9 in the format string with values from |subst|.
// Additionally, any number of consecutive '$' characters is replaced by that
« no previous file with comments | « no previous file | base/strings/string_util.cc » ('j') | base/strings/string_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698