| 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 #include "base/strings/string_split.h" | 5 #include "base/strings/string_split.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/third_party/icu/icu_utf.h" | 10 #include "base/third_party/icu/icu_utf.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return false; // no value | 73 return false; // no value |
| 74 } | 74 } |
| 75 std::string values_string(remains, begin_values_pos, | 75 std::string values_string(remains, begin_values_pos, |
| 76 remains.size() - begin_values_pos); | 76 remains.size() - begin_values_pos); |
| 77 | 77 |
| 78 // Construct the values vector. | 78 // Construct the values vector. |
| 79 values->push_back(values_string); | 79 values->push_back(values_string); |
| 80 return true; | 80 return true; |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool SplitStringIntoKeyValuePairs( | 83 bool SplitStringIntoKeyValuePairs(const std::string& line, |
| 84 const std::string& line, | 84 char key_value_delimiter, |
| 85 char key_value_delimiter, | 85 char key_value_pair_delimiter, |
| 86 char key_value_pair_delimiter, | 86 StringPairs* key_value_pairs) { |
| 87 std::vector<std::pair<std::string, std::string> >* kv_pairs) { | 87 key_value_pairs->clear(); |
| 88 kv_pairs->clear(); | |
| 89 | 88 |
| 90 std::vector<std::string> pairs; | 89 std::vector<std::string> pairs; |
| 91 SplitString(line, key_value_pair_delimiter, &pairs); | 90 SplitString(line, key_value_pair_delimiter, &pairs); |
| 92 | 91 |
| 93 bool success = true; | 92 bool success = true; |
| 94 for (size_t i = 0; i < pairs.size(); ++i) { | 93 for (size_t i = 0; i < pairs.size(); ++i) { |
| 95 // Empty pair. SplitStringIntoKeyValues is more strict about an empty pair | 94 // Empty pair. SplitStringIntoKeyValues is more strict about an empty pair |
| 96 // line, so continue with the next pair. | 95 // line, so continue with the next pair. |
| 97 if (pairs[i].empty()) | 96 if (pairs[i].empty()) |
| 98 continue; | 97 continue; |
| 99 | 98 |
| 100 std::string key; | 99 std::string key; |
| 101 std::vector<std::string> value; | 100 std::vector<std::string> value; |
| 102 if (!SplitStringIntoKeyValues(pairs[i], | 101 if (!SplitStringIntoKeyValues(pairs[i], |
| 103 key_value_delimiter, | 102 key_value_delimiter, |
| 104 &key, &value)) { | 103 &key, &value)) { |
| 105 // Don't return here, to allow for keys without associated | 104 // Don't return here, to allow for keys without associated |
| 106 // values; just record that our split failed. | 105 // values; just record that our split failed. |
| 107 success = false; | 106 success = false; |
| 108 } | 107 } |
| 109 DCHECK_LE(value.size(), 1U); | 108 DCHECK_LE(value.size(), 1U); |
| 110 kv_pairs->push_back( | 109 key_value_pairs->push_back( |
| 111 make_pair(key, value.empty() ? std::string() : value[0])); | 110 make_pair(key, value.empty() ? std::string() : value[0])); |
| 112 } | 111 } |
| 113 return success; | 112 return success; |
| 114 } | 113 } |
| 115 | 114 |
| 116 template <typename STR> | 115 template <typename STR> |
| 117 static void SplitStringUsingSubstrT(const STR& str, | 116 static void SplitStringUsingSubstrT(const STR& str, |
| 118 const STR& s, | 117 const STR& s, |
| 119 std::vector<STR>* r) { | 118 std::vector<STR>* r) { |
| 120 r->clear(); | 119 r->clear(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 std::vector<string16>* result) { | 210 std::vector<string16>* result) { |
| 212 SplitStringAlongWhitespaceT(str, result); | 211 SplitStringAlongWhitespaceT(str, result); |
| 213 } | 212 } |
| 214 | 213 |
| 215 void SplitStringAlongWhitespace(const std::string& str, | 214 void SplitStringAlongWhitespace(const std::string& str, |
| 216 std::vector<std::string>* result) { | 215 std::vector<std::string>* result) { |
| 217 SplitStringAlongWhitespaceT(str, result); | 216 SplitStringAlongWhitespaceT(str, result); |
| 218 } | 217 } |
| 219 | 218 |
| 220 } // namespace base | 219 } // namespace base |
| OLD | NEW |