| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_STRINGS_STRING_SPLIT_H_ | 5 #ifndef BASE_STRINGS_STRING_SPLIT_H_ |
| 6 #define BASE_STRINGS_STRING_SPLIT_H_ | 6 #define BASE_STRINGS_STRING_SPLIT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // removes whitespace leading each key and trailing each value. Returns true | 83 // removes whitespace leading each key and trailing each value. Returns true |
| 84 // only if each pair has a non-empty key and value. |key_value_pairs| will | 84 // only if each pair has a non-empty key and value. |key_value_pairs| will |
| 85 // include ("","") pairs for entries without |key_value_delimiter|. | 85 // include ("","") pairs for entries without |key_value_delimiter|. |
| 86 BASE_EXPORT bool SplitStringIntoKeyValuePairs(StringPiece input, | 86 BASE_EXPORT bool SplitStringIntoKeyValuePairs(StringPiece input, |
| 87 char key_value_delimiter, | 87 char key_value_delimiter, |
| 88 char key_value_pair_delimiter, | 88 char key_value_pair_delimiter, |
| 89 StringPairs* key_value_pairs); | 89 StringPairs* key_value_pairs); |
| 90 | 90 |
| 91 // Similar to SplitString, but use a substring delimiter instead of a list of | 91 // Similar to SplitString, but use a substring delimiter instead of a list of |
| 92 // characters that are all possible delimiters. | 92 // characters that are all possible delimiters. |
| 93 // | 93 BASE_EXPORT std::vector<string16> SplitStringUsingSubstr( |
| 94 // TODO(brettw) this should probably be changed and expanded to provide a | 94 StringPiece16 input, |
| 95 // mirror of the SplitString[Piece] API above, just with the different | 95 StringPiece16 delimiter, |
| 96 // delimiter handling. | 96 WhitespaceHandling whitespace, |
| 97 BASE_EXPORT void SplitStringUsingSubstr(StringPiece16 input, | 97 SplitResult result_type); |
| 98 StringPiece16 delimiter, | 98 BASE_EXPORT std::vector<std::string> SplitStringUsingSubstr( |
| 99 std::vector<string16>* result); | 99 StringPiece input, |
| 100 BASE_EXPORT void SplitStringUsingSubstr(StringPiece input, | 100 StringPiece delimiter, |
| 101 StringPiece delimiter, | 101 WhitespaceHandling whitespace, |
| 102 std::vector<std::string>* result); | 102 SplitResult result_type); |
| 103 | 103 |
| 104 // Like SplitStringUsingSubstr above except it returns a vector of StringPieces | 104 // Like SplitStringUsingSubstr above except it returns a vector of StringPieces |
| 105 // which reference the original buffer without copying. Although you have to be | 105 // which reference the original buffer without copying. Although you have to be |
| 106 // careful to keep the original string unmodified, this provides an efficient | 106 // careful to keep the original string unmodified, this provides an efficient |
| 107 // way to iterate through tokens in a string. | 107 // way to iterate through tokens in a string. |
| 108 // | 108 // |
| 109 // To iterate through all newline-separated tokens in an input string: | 109 // To iterate through all newline-separated tokens in an input string: |
| 110 // | 110 // |
| 111 // for (const auto& cur : | 111 // for (const auto& cur : |
| 112 // base::SplitStringUsingSubstr(input, "\r\n", | 112 // base::SplitStringUsingSubstr(input, "\r\n", |
| 113 // base::KEEP_WHITESPACE, | 113 // base::KEEP_WHITESPACE, |
| 114 // base::SPLIT_WANT_NONEMPTY)) { | 114 // base::SPLIT_WANT_NONEMPTY)) { |
| 115 // ... | 115 // ... |
| 116 BASE_EXPORT std::vector<StringPiece16> SplitStringPieceUsingSubstr( | 116 BASE_EXPORT std::vector<StringPiece16> SplitStringPieceUsingSubstr( |
| 117 StringPiece16 input, | 117 StringPiece16 input, |
| 118 StringPiece16 delimiter, | 118 StringPiece16 delimiter, |
| 119 WhitespaceHandling whitespace, | 119 WhitespaceHandling whitespace, |
| 120 SplitResult result_type); | 120 SplitResult result_type); |
| 121 BASE_EXPORT std::vector<StringPiece> SplitStringPieceUsingSubstr( | 121 BASE_EXPORT std::vector<StringPiece> SplitStringPieceUsingSubstr( |
| 122 StringPiece input, | 122 StringPiece input, |
| 123 StringPiece delimiter, | 123 StringPiece delimiter, |
| 124 WhitespaceHandling whitespace, | 124 WhitespaceHandling whitespace, |
| 125 SplitResult result_type); | 125 SplitResult result_type); |
| 126 | 126 |
| 127 } // namespace base | 127 } // namespace base |
| 128 | 128 |
| 129 #endif // BASE_STRINGS_STRING_SPLIT_H_ | 129 #endif // BASE_STRINGS_STRING_SPLIT_H_ |
| OLD | NEW |