| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/third_party/icu/icu_utf.h" | 9 #include "base/third_party/icu/icu_utf.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.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 size_t last = 0; | 19 size_t last = 0; |
| 20 size_t i; |
| 20 size_t c = str.size(); | 21 size_t c = str.size(); |
| 21 for (size_t i = 0; i <= c; ++i) { | 22 for (i = 0; i <= c; ++i) { |
| 22 if (i == c || str[i] == s) { | 23 if (i == c || str[i] == s) { |
| 23 STR tmp(str, last, i - last); | 24 size_t len = i - last; |
| 24 if (trim_whitespace) | 25 STR tmp = str.substr(last, len); |
| 25 TrimWhitespace(tmp, TRIM_ALL, &tmp); | 26 if (trim_whitespace) { |
| 26 // Avoid converting an empty or all-whitespace source string into a vector | 27 STR t_tmp; |
| 27 // of one empty string. | 28 TrimWhitespace(tmp, TRIM_ALL, &t_tmp); |
| 28 if (i != c || !r->empty() || !tmp.empty()) | 29 r->push_back(t_tmp); |
| 30 } else { |
| 29 r->push_back(tmp); | 31 r->push_back(tmp); |
| 32 } |
| 30 last = i + 1; | 33 last = i + 1; |
| 31 } | 34 } |
| 32 } | 35 } |
| 33 } | 36 } |
| 34 | 37 |
| 35 void SplitString(const string16& str, | 38 void SplitString(const string16& str, |
| 36 char16 c, | 39 char16 c, |
| 37 std::vector<string16>* r) { | 40 std::vector<string16>* r) { |
| 38 DCHECK(CBU16_IS_SINGLE(c)); | 41 DCHECK(CBU16_IS_SINGLE(c)); |
| 39 SplitStringT(str, c, true, r); | 42 SplitStringT(str, c, true, r); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 std::vector<string16>* result) { | 210 std::vector<string16>* result) { |
| 208 SplitStringAlongWhitespaceT(str, result); | 211 SplitStringAlongWhitespaceT(str, result); |
| 209 } | 212 } |
| 210 | 213 |
| 211 void SplitStringAlongWhitespace(const std::string& str, | 214 void SplitStringAlongWhitespace(const std::string& str, |
| 212 std::vector<std::string>* result) { | 215 std::vector<std::string>* result) { |
| 213 SplitStringAlongWhitespaceT(str, result); | 216 SplitStringAlongWhitespaceT(str, result); |
| 214 } | 217 } |
| 215 | 218 |
| 216 } // namespace base | 219 } // namespace base |
| OLD | NEW |