OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/string_split.h" | 5 #include "base/string_split.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // Don't return here, to allow for keys without associated | 64 // Don't return here, to allow for keys without associated |
65 // values; just record that our split failed. | 65 // values; just record that our split failed. |
66 success = false; | 66 success = false; |
67 } | 67 } |
68 DCHECK_LE(value.size(), 1U); | 68 DCHECK_LE(value.size(), 1U); |
69 kv_pairs->push_back(make_pair(key, value.empty()? "" : value[0])); | 69 kv_pairs->push_back(make_pair(key, value.empty()? "" : value[0])); |
70 } | 70 } |
71 return success; | 71 return success; |
72 } | 72 } |
73 | 73 |
| 74 template <typename STR> |
| 75 static void SplitStringUsingSubstrT(const STR& str, |
| 76 const STR& s, |
| 77 std::vector<STR>* r) { |
| 78 typename STR::size_type begin_index = 0; |
| 79 while (true) { |
| 80 const typename STR::size_type end_index = str.find(s, begin_index); |
| 81 if (end_index == STR::npos) { |
| 82 const STR term = str.substr(begin_index); |
| 83 STR tmp; |
| 84 TrimWhitespace(term, TRIM_ALL, &tmp); |
| 85 r->push_back(tmp); |
| 86 return; |
| 87 } |
| 88 const STR term = str.substr(begin_index, end_index - begin_index); |
| 89 STR tmp; |
| 90 TrimWhitespace(term, TRIM_ALL, &tmp); |
| 91 r->push_back(tmp); |
| 92 begin_index = end_index + s.size(); |
| 93 } |
| 94 } |
| 95 |
| 96 void SplitStringUsingSubstr(const string16& str, |
| 97 const string16& s, |
| 98 std::vector<string16>* r) { |
| 99 SplitStringUsingSubstrT(str, s, r); |
| 100 } |
| 101 |
| 102 void SplitStringUsingSubstr(const std::string& str, |
| 103 const std::string& s, |
| 104 std::vector<std::string>* r) { |
| 105 SplitStringUsingSubstrT(str, s, r); |
| 106 } |
| 107 |
74 } // namespace base | 108 } // namespace base |
OLD | NEW |