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

Side by Side Diff: base/string_split.cc

Issue 3284005: base: Move SplitStringUsingSubstr functions from string_util.h to string_split.h (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: fix base_unittests Created 10 years, 3 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 unified diff | Download patch
« no previous file with comments | « base/string_split.h ('k') | base/string_split_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « base/string_split.h ('k') | base/string_split_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698