| 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 #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 { |
| 13 |
| 12 template<typename STR> | 14 template<typename STR> |
| 13 static void SplitStringT(const STR& str, | 15 static void SplitStringT(const STR& str, |
| 14 const typename STR::value_type s, | 16 const typename STR::value_type s, |
| 15 bool trim_whitespace, | 17 bool trim_whitespace, |
| 16 std::vector<STR>* r) { | 18 std::vector<STR>* r) { |
| 17 size_t last = 0; | 19 size_t last = 0; |
| 18 size_t i; | 20 size_t i; |
| 19 size_t c = str.size(); | 21 size_t c = str.size(); |
| 20 for (i = 0; i <= c; ++i) { | 22 for (i = 0; i <= c; ++i) { |
| 21 if (i == c || str[i] == s) { | 23 if (i == c || str[i] == s) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 48 } | 50 } |
| 49 #endif | 51 #endif |
| 50 | 52 |
| 51 void SplitString(const std::string& str, | 53 void SplitString(const std::string& str, |
| 52 char c, | 54 char c, |
| 53 std::vector<std::string>* r) { | 55 std::vector<std::string>* r) { |
| 54 DCHECK(c >= 0 && c < 0x7F); | 56 DCHECK(c >= 0 && c < 0x7F); |
| 55 SplitStringT(str, c, true, r); | 57 SplitStringT(str, c, true, r); |
| 56 } | 58 } |
| 57 | 59 |
| 58 namespace base { | |
| 59 | |
| 60 bool SplitStringIntoKeyValues( | 60 bool SplitStringIntoKeyValues( |
| 61 const std::string& line, | 61 const std::string& line, |
| 62 char key_value_delimiter, | 62 char key_value_delimiter, |
| 63 std::string* key, std::vector<std::string>* values) { | 63 std::string* key, std::vector<std::string>* values) { |
| 64 key->clear(); | 64 key->clear(); |
| 65 values->clear(); | 65 values->clear(); |
| 66 | 66 |
| 67 // Find the key string. | 67 // Find the key string. |
| 68 size_t end_key_pos = line.find_first_of(key_value_delimiter); | 68 size_t end_key_pos = line.find_first_of(key_value_delimiter); |
| 69 if (end_key_pos == std::string::npos) { | 69 if (end_key_pos == std::string::npos) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 void SplitStringDontTrim(const std::string& str, | 171 void SplitStringDontTrim(const std::string& str, |
| 172 char c, | 172 char c, |
| 173 std::vector<std::string>* r) { | 173 std::vector<std::string>* r) { |
| 174 DCHECK(IsStringUTF8(str)); | 174 DCHECK(IsStringUTF8(str)); |
| 175 DCHECK(c >= 0 && c < 0x7F); | 175 DCHECK(c >= 0 && c < 0x7F); |
| 176 SplitStringT(str, c, false, r); | 176 SplitStringT(str, c, false, r); |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace base | 179 } // namespace base |
| OLD | NEW |