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

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: Add WhitespaceHandling and SplitResult to SplitStringPieceUsingSubstr Created 4 years, 12 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_split.cc » ('j') | no next file with comments »
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..ec9f24604a6339051f9aa9086b3460c71e983559 100644
--- a/base/strings/string_split.h
+++ b/base/strings/string_split.h
@@ -101,6 +101,29 @@ 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::KEEP_WHITESPACE,
+// base::SPLIT_WANT_NONEMPTY)) {
+// ...
+BASE_EXPORT std::vector<StringPiece16> SplitStringPieceUsingSubstr(
+ StringPiece16 input,
+ StringPiece16 delimiter,
+ WhitespaceHandling whitespace,
+ SplitResult result_type);
+BASE_EXPORT std::vector<StringPiece> SplitStringPieceUsingSubstr(
+ StringPiece input,
+ StringPiece delimiter,
+ WhitespaceHandling whitespace,
+ SplitResult result_type);
+
} // namespace base
#endif // BASE_STRINGS_STRING_SPLIT_H_
« no previous file with comments | « no previous file | base/strings/string_split.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698