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_util.h" | 5 #include "base/string_util.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <ctype.h> | 9 #include <ctype.h> |
10 #include <errno.h> | 10 #include <errno.h> |
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 SplitStringT(str, s, false, r); | 1317 SplitStringT(str, s, false, r); |
1318 } | 1318 } |
1319 #endif | 1319 #endif |
1320 | 1320 |
1321 void SplitStringDontTrim(const std::string& str, | 1321 void SplitStringDontTrim(const std::string& str, |
1322 char s, | 1322 char s, |
1323 std::vector<std::string>* r) { | 1323 std::vector<std::string>* r) { |
1324 SplitStringT(str, s, false, r); | 1324 SplitStringT(str, s, false, r); |
1325 } | 1325 } |
1326 | 1326 |
1327 template <typename STR> | |
1328 static void SplitStringUsingSubstrT(const STR& str, | |
1329 const STR& s, | |
1330 std::vector<STR>* r) { | |
1331 typename STR::size_type begin_index = 0; | |
1332 while (true) { | |
1333 const typename STR::size_type end_index = str.find(s, begin_index); | |
1334 if (end_index == STR::npos) { | |
1335 const STR term = str.substr(begin_index); | |
1336 STR tmp; | |
1337 TrimWhitespace(term, TRIM_ALL, &tmp); | |
1338 r->push_back(tmp); | |
1339 return; | |
1340 } | |
1341 const STR term = str.substr(begin_index, end_index - begin_index); | |
1342 STR tmp; | |
1343 TrimWhitespace(term, TRIM_ALL, &tmp); | |
1344 r->push_back(tmp); | |
1345 begin_index = end_index + s.size(); | |
1346 } | |
1347 } | |
1348 | |
1349 void SplitStringUsingSubstr(const string16& str, | |
1350 const string16& s, | |
1351 std::vector<string16>* r) { | |
1352 SplitStringUsingSubstrT(str, s, r); | |
1353 } | |
1354 | |
1355 void SplitStringUsingSubstr(const std::string& str, | |
1356 const std::string& s, | |
1357 std::vector<std::string>* r) { | |
1358 SplitStringUsingSubstrT(str, s, r); | |
1359 } | |
1360 | |
1361 std::vector<string16> SplitStringUsingSubstr(const string16& str, | |
1362 const string16& s) { | |
1363 std::vector<string16> result; | |
1364 SplitStringUsingSubstr(str, s, &result); | |
1365 return result; | |
1366 } | |
1367 | |
1368 std::vector<std::string> SplitStringUsingSubstr(const std::string& str, | |
1369 const std::string& s) { | |
1370 std::vector<std::string> result; | |
1371 SplitStringUsingSubstr(str, s, &result); | |
1372 return result; | |
1373 } | |
1374 | |
1375 template<typename STR> | 1327 template<typename STR> |
1376 static size_t TokenizeT(const STR& str, | 1328 static size_t TokenizeT(const STR& str, |
1377 const STR& delimiters, | 1329 const STR& delimiters, |
1378 std::vector<STR>* tokens) { | 1330 std::vector<STR>* tokens) { |
1379 tokens->clear(); | 1331 tokens->clear(); |
1380 | 1332 |
1381 typename STR::size_type start = str.find_first_not_of(delimiters); | 1333 typename STR::size_type start = str.find_first_not_of(delimiters); |
1382 while (start != STR::npos) { | 1334 while (start != STR::npos) { |
1383 typename STR::size_type end = str.find_first_of(delimiters, start + 1); | 1335 typename STR::size_type end = str.find_first_of(delimiters, start + 1); |
1384 if (end == STR::npos) { | 1336 if (end == STR::npos) { |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1888 // Each input byte creates two output hex characters. | 1840 // Each input byte creates two output hex characters. |
1889 std::string ret(size * 2, '\0'); | 1841 std::string ret(size * 2, '\0'); |
1890 | 1842 |
1891 for (size_t i = 0; i < size; ++i) { | 1843 for (size_t i = 0; i < size; ++i) { |
1892 char b = reinterpret_cast<const char*>(bytes)[i]; | 1844 char b = reinterpret_cast<const char*>(bytes)[i]; |
1893 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; | 1845 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; |
1894 ret[(i * 2) + 1] = kHexChars[b & 0xf]; | 1846 ret[(i * 2) + 1] = kHexChars[b & 0xf]; |
1895 } | 1847 } |
1896 return ret; | 1848 return ret; |
1897 } | 1849 } |
OLD | NEW |