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

Unified Diff: base/strings/string_util.cc

Issue 2691193002: Added StringPiece overloads for base::JoinString. (Closed)
Patch Set: 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
Index: base/strings/string_util.cc
diff --git a/base/strings/string_util.cc b/base/strings/string_util.cc
index cb668ed7fff4f60f76291a0a19d478fb9faaacd5..a2e043045b6de77f9922d46a6b0640f0c5714636 100644
--- a/base/strings/string_util.cc
+++ b/base/strings/string_util.cc
@@ -853,7 +853,7 @@ char16* WriteInto(string16* str, size_t length_with_null) {
return WriteIntoT(str, length_with_null);
}
-template<typename STR>
+template <typename STR>
static STR JoinStringT(const std::vector<STR>& parts,
BasicStringPiece<STR> sep) {
if (parts.empty())
@@ -871,6 +871,24 @@ static STR JoinStringT(const std::vector<STR>& parts,
return result;
}
+template <typename STR>
+static STR JoinStringPieceT(const std::vector<BasicStringPiece<STR>>& parts,
+ BasicStringPiece<STR> sep) {
+ if (parts.empty())
+ return STR();
+
+ STR result(parts[0].data(), parts[0].size());
+ auto iter = parts.begin();
+ ++iter;
+
+ for (; iter != parts.end(); ++iter) {
+ sep.AppendToString(&result);
danakj 2017/02/16 16:34:32 Just throwing it out there, not for this CL, but:
danakj 2017/02/16 16:36:21 Ohh I see actually at the site that you deleted th
Matt Giuca 2017/02/16 23:51:11 Yes! Maybe you missed this in my original email:
danakj 2017/02/16 23:53:28 Oops, ya I missed that. I super doubt walking the
+ iter->AppendToString(&result);
+ }
+
+ return result;
+}
+
std::string JoinString(const std::vector<std::string>& parts,
StringPiece separator) {
return JoinStringT(parts, separator);
@@ -881,6 +899,16 @@ string16 JoinString(const std::vector<string16>& parts,
return JoinStringT(parts, separator);
}
+std::string JoinStringPiece(const std::vector<StringPiece>& parts,
+ StringPiece separator) {
+ return JoinStringPieceT(parts, separator);
+}
+
+string16 JoinStringPiece(const std::vector<StringPiece16>& parts,
+ StringPiece16 separator) {
+ return JoinStringPieceT(parts, separator);
+}
+
template<class FormatStringType, class OutStringType>
OutStringType DoReplaceStringPlaceholders(
const FormatStringType& format_string,

Powered by Google App Engine
This is Rietveld 408576698