Chromium Code Reviews| 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" |
| 11 | 11 |
| 12 namespace base { | 12 namespace base { |
| 13 | 13 |
| 14 template<typename STR> | 14 template<typename STR> |
| 15 static void SplitStringT(const STR& str, | 15 static void SplitStringT(const STR& str, |
| 16 const typename STR::value_type s, | 16 const typename STR::value_type s, |
| 17 bool trim_whitespace, | 17 bool trim_whitespace, |
| 18 std::vector<STR>* r) { | 18 std::vector<STR>* r) { |
| 19 r->clear(); | 19 r->clear(); |
| 20 size_t last = 0; | 20 size_t last = 0; |
| 21 size_t c = str.size(); | 21 size_t c = str.size(); |
| 22 for (size_t i = 0; i <= c; ++i) { | 22 for (size_t i = 0; i <= c; ++i) { |
| 23 if (i == c || str[i] == s) { | 23 if (i == c || str[i] == s) { |
| 24 STR tmp(str, last, i - last); | 24 STR tmp(str, last, i - last); |
| 25 if (trim_whitespace) | 25 if (trim_whitespace) |
| 26 TrimWhitespace(tmp, TRIM_ALL, &tmp); | 26 base::TrimWhitespace(tmp, TRIM_ALL, &tmp); |
|
viettrungluu
2014/02/28 23:44:14
base:: unnecessary. You're already in that namespa
| |
| 27 // Avoid converting an empty or all-whitespace source string into a vector | 27 // Avoid converting an empty or all-whitespace source string into a vector |
| 28 // of one empty string. | 28 // of one empty string. |
| 29 if (i != c || !r->empty() || !tmp.empty()) | 29 if (i != c || !r->empty() || !tmp.empty()) |
| 30 r->push_back(tmp); | 30 r->push_back(tmp); |
| 31 last = i + 1; | 31 last = i + 1; |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 void SplitString(const string16& str, | 36 void SplitString(const string16& str, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 static void SplitStringUsingSubstrT(const STR& str, | 116 static void SplitStringUsingSubstrT(const STR& str, |
| 117 const STR& s, | 117 const STR& s, |
| 118 std::vector<STR>* r) { | 118 std::vector<STR>* r) { |
| 119 r->clear(); | 119 r->clear(); |
| 120 typename STR::size_type begin_index = 0; | 120 typename STR::size_type begin_index = 0; |
| 121 while (true) { | 121 while (true) { |
| 122 const typename STR::size_type end_index = str.find(s, begin_index); | 122 const typename STR::size_type end_index = str.find(s, begin_index); |
| 123 if (end_index == STR::npos) { | 123 if (end_index == STR::npos) { |
| 124 const STR term = str.substr(begin_index); | 124 const STR term = str.substr(begin_index); |
| 125 STR tmp; | 125 STR tmp; |
| 126 TrimWhitespace(term, TRIM_ALL, &tmp); | 126 base::TrimWhitespace(term, TRIM_ALL, &tmp); |
|
viettrungluu
2014/02/28 23:44:14
"
| |
| 127 r->push_back(tmp); | 127 r->push_back(tmp); |
| 128 return; | 128 return; |
| 129 } | 129 } |
| 130 const STR term = str.substr(begin_index, end_index - begin_index); | 130 const STR term = str.substr(begin_index, end_index - begin_index); |
| 131 STR tmp; | 131 STR tmp; |
| 132 TrimWhitespace(term, TRIM_ALL, &tmp); | 132 base::TrimWhitespace(term, TRIM_ALL, &tmp); |
|
viettrungluu
2014/02/28 23:44:14
"
| |
| 133 r->push_back(tmp); | 133 r->push_back(tmp); |
| 134 begin_index = end_index + s.size(); | 134 begin_index = end_index + s.size(); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 void SplitStringUsingSubstr(const string16& str, | 138 void SplitStringUsingSubstr(const string16& str, |
| 139 const string16& s, | 139 const string16& s, |
| 140 std::vector<string16>* r) { | 140 std::vector<string16>* r) { |
| 141 SplitStringUsingSubstrT(str, s, r); | 141 SplitStringUsingSubstrT(str, s, r); |
| 142 } | 142 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 std::vector<string16>* result) { | 210 std::vector<string16>* result) { |
| 211 SplitStringAlongWhitespaceT(str, result); | 211 SplitStringAlongWhitespaceT(str, result); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void SplitStringAlongWhitespace(const std::string& str, | 214 void SplitStringAlongWhitespace(const std::string& str, |
| 215 std::vector<std::string>* result) { | 215 std::vector<std::string>* result) { |
| 216 SplitStringAlongWhitespaceT(str, result); | 216 SplitStringAlongWhitespaceT(str, result); |
| 217 } | 217 } |
| 218 | 218 |
| 219 } // namespace base | 219 } // namespace base |
| OLD | NEW |