Chromium Code Reviews| Index: base/strings/string_split.cc |
| diff --git a/base/strings/string_split.cc b/base/strings/string_split.cc |
| index 4253e2f8f86b7ed393dfdf66193b91b489176bf8..623766b09aef2f6f0d98d2324369b244870495e4 100644 |
| --- a/base/strings/string_split.cc |
| +++ b/base/strings/string_split.cc |
| @@ -128,10 +128,10 @@ bool AppendStringKeyValue(StringPiece input, |
| return true; |
| } |
| -template <typename Str> |
| +template <typename Str, typename OutputStringType> |
| void SplitStringUsingSubstrT(BasicStringPiece<Str> input, |
| BasicStringPiece<Str> delimiter, |
| - std::vector<Str>* result) { |
| + std::vector<OutputStringType>* result) { |
| using Piece = BasicStringPiece<Str>; |
| using size_type = typename Piece::size_type; |
| @@ -143,12 +143,12 @@ void SplitStringUsingSubstrT(BasicStringPiece<Str> input, |
| // No delimiter, use the rest of the string. |
| Piece term = TrimString(input.substr(begin_index), |
| WhitespaceForType<Str>(), TRIM_ALL); |
| - result->push_back(term.as_string()); |
| + result->push_back(PieceToOutputType<Str, OutputStringType>(term)); |
| return; |
| } |
| Piece term = TrimString(input.substr(begin_index, end_index - begin_index), |
| WhitespaceForType<Str>(), TRIM_ALL); |
| - result->push_back(term.as_string()); |
| + result->push_back(PieceToOutputType<Str, OutputStringType>(term)); |
| begin_index = end_index + delimiter.size(); |
| } |
| } |
| @@ -237,4 +237,19 @@ void SplitStringUsingSubstr(StringPiece input, |
| SplitStringUsingSubstrT(input, delimiter, result); |
| } |
| +std::vector<StringPiece16> SplitStringPieceUsingSubstr( |
| + StringPiece16 input, |
| + StringPiece16 delimiter) { |
|
mef
2015/12/28 17:29:55
Would it make sense to take a pointer to an output
brettw
2015/12/29 04:07:14
Return value optimization should take care of this
mef
2015/12/30 19:36:58
Acknowledged.
|
| + std::vector<StringPiece16> result; |
| + SplitStringUsingSubstrT(input, delimiter, &result); |
| + return result; |
| +} |
| + |
| +std::vector<StringPiece> SplitStringPieceUsingSubstr(StringPiece input, |
| + StringPiece delimiter) { |
| + std::vector<StringPiece> result; |
| + SplitStringUsingSubstrT(input, delimiter, &result); |
| + return result; |
| +} |
| + |
| } // namespace base |