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

Unified Diff: base/strings/string_split.h

Issue 1549063003: Don't unnecessarily copy strings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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_split.cc » ('j') | base/strings/string_split.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/strings/string_split.h
diff --git a/base/strings/string_split.h b/base/strings/string_split.h
index 2a0c79561b85cca9561bbc80cf8e709e7ed2eace..e4574bac52f50e836ce52b4488b0e6321d06b5bb 100644
--- a/base/strings/string_split.h
+++ b/base/strings/string_split.h
@@ -101,6 +101,23 @@ BASE_EXPORT void SplitStringUsingSubstr(StringPiece input,
StringPiece delimiter,
std::vector<std::string>* result);
+// Like SplitStringUsingSubstr above except it returns a vector of StringPieces
+// which reference the original buffer without copying. Although you have to be
+// careful to keep the original string unmodified, this provides an efficient
+// way to iterate through tokens in a string.
+//
+// To iterate through all newline-separated tokens in an input string:
+//
+// for (const auto& cur :
+// base::SplitStringUsingSubstr(input, "\r\n")) {
+// ...
+BASE_EXPORT std::vector<StringPiece16> SplitStringPieceUsingSubstr(
brettw 2015/12/29 22:14:40 I'd like to make this a mirror of SplitString[Piec
+ StringPiece16 input,
+ StringPiece16 delimiter);
+BASE_EXPORT std::vector<StringPiece> SplitStringPieceUsingSubstr(
+ StringPiece input,
+ StringPiece delimiter);
+
} // namespace base
#endif // BASE_STRINGS_STRING_SPLIT_H_
« no previous file with comments | « no previous file | base/strings/string_split.cc » ('j') | base/strings/string_split.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698