| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 } | 1294 } |
| 1295 } | 1295 } |
| 1296 } | 1296 } |
| 1297 | 1297 |
| 1298 void SplitString(const std::wstring& str, | 1298 void SplitString(const std::wstring& str, |
| 1299 wchar_t s, | 1299 wchar_t s, |
| 1300 std::vector<std::wstring>* r) { | 1300 std::vector<std::wstring>* r) { |
| 1301 SplitStringT(str, s, true, r); | 1301 SplitStringT(str, s, true, r); |
| 1302 } | 1302 } |
| 1303 | 1303 |
| 1304 #if !defined(WCHAR_T_IS_UTF16) |
| 1305 void SplitString(const string16& str, |
| 1306 char16 s, |
| 1307 std::vector<string16>* r) { |
| 1308 SplitStringT(str, s, true, r); |
| 1309 } |
| 1310 #endif |
| 1311 |
| 1304 void SplitString(const std::string& str, | 1312 void SplitString(const std::string& str, |
| 1305 char s, | 1313 char s, |
| 1306 std::vector<std::string>* r) { | 1314 std::vector<std::string>* r) { |
| 1307 SplitStringT(str, s, true, r); | 1315 SplitStringT(str, s, true, r); |
| 1308 } | 1316 } |
| 1309 | 1317 |
| 1310 void SplitStringDontTrim(const std::wstring& str, | 1318 void SplitStringDontTrim(const std::wstring& str, |
| 1311 wchar_t s, | 1319 wchar_t s, |
| 1312 std::vector<std::wstring>* r) { | 1320 std::vector<std::wstring>* r) { |
| 1313 SplitStringT(str, s, false, r); | 1321 SplitStringT(str, s, false, r); |
| 1314 } | 1322 } |
| 1315 | 1323 |
| 1324 #if !defined(WCHAR_T_IS_UTF16) |
| 1325 void SplitStringDontTrim(const string16& str, |
| 1326 char16 s, |
| 1327 std::vector<string16>* r) { |
| 1328 SplitStringT(str, s, false, r); |
| 1329 } |
| 1330 #endif |
| 1331 |
| 1316 void SplitStringDontTrim(const std::string& str, | 1332 void SplitStringDontTrim(const std::string& str, |
| 1317 char s, | 1333 char s, |
| 1318 std::vector<std::string>* r) { | 1334 std::vector<std::string>* r) { |
| 1319 SplitStringT(str, s, false, r); | 1335 SplitStringT(str, s, false, r); |
| 1320 } | 1336 } |
| 1321 | 1337 |
| 1322 template<typename STR> | 1338 template<typename STR> |
| 1323 static STR JoinStringT(const std::vector<STR>& parts, | 1339 static STR JoinStringT(const std::vector<STR>& parts, |
| 1324 typename STR::value_type sep) { | 1340 typename STR::value_type sep) { |
| 1325 if (parts.size() == 0) return STR(); | 1341 if (parts.size() == 0) return STR(); |
| 1326 | 1342 |
| 1327 STR result(parts[0]); | 1343 STR result(parts[0]); |
| 1328 typename std::vector<STR>::const_iterator iter = parts.begin(); | 1344 typename std::vector<STR>::const_iterator iter = parts.begin(); |
| 1329 ++iter; | 1345 ++iter; |
| 1330 | 1346 |
| 1331 for (; iter != parts.end(); ++iter) { | 1347 for (; iter != parts.end(); ++iter) { |
| 1332 result += sep; | 1348 result += sep; |
| 1333 result += *iter; | 1349 result += *iter; |
| 1334 } | 1350 } |
| 1335 | 1351 |
| 1336 return result; | 1352 return result; |
| 1337 } | 1353 } |
| 1338 | 1354 |
| 1339 std::string JoinString(const std::vector<std::string>& parts, char sep) { | 1355 std::string JoinString(const std::vector<std::string>& parts, char sep) { |
| 1340 return JoinStringT(parts, sep); | 1356 return JoinStringT(parts, sep); |
| 1341 } | 1357 } |
| 1342 | 1358 |
| 1359 #if !defined(WCHAR_T_IS_UTF16) |
| 1360 string16 JoinString(const std::vector<string16>& parts, char sep) { |
| 1361 return JoinStringT(parts, sep); |
| 1362 } |
| 1363 #endif |
| 1364 |
| 1343 std::wstring JoinString(const std::vector<std::wstring>& parts, wchar_t sep) { | 1365 std::wstring JoinString(const std::vector<std::wstring>& parts, wchar_t sep) { |
| 1344 return JoinStringT(parts, sep); | 1366 return JoinStringT(parts, sep); |
| 1345 } | 1367 } |
| 1346 | 1368 |
| 1347 template<typename STR> | 1369 template<typename STR> |
| 1348 void SplitStringAlongWhitespaceT(const STR& str, std::vector<STR>* result) { | 1370 void SplitStringAlongWhitespaceT(const STR& str, std::vector<STR>* result) { |
| 1349 const size_t length = str.length(); | 1371 const size_t length = str.length(); |
| 1350 if (!length) | 1372 if (!length) |
| 1351 return; | 1373 return; |
| 1352 | 1374 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1382 result->push_back( | 1404 result->push_back( |
| 1383 str.substr(last_non_ws_start, length - last_non_ws_start)); | 1405 str.substr(last_non_ws_start, length - last_non_ws_start)); |
| 1384 } | 1406 } |
| 1385 } | 1407 } |
| 1386 | 1408 |
| 1387 void SplitStringAlongWhitespace(const std::wstring& str, | 1409 void SplitStringAlongWhitespace(const std::wstring& str, |
| 1388 std::vector<std::wstring>* result) { | 1410 std::vector<std::wstring>* result) { |
| 1389 SplitStringAlongWhitespaceT(str, result); | 1411 SplitStringAlongWhitespaceT(str, result); |
| 1390 } | 1412 } |
| 1391 | 1413 |
| 1414 #if !defined(WCHAR_T_IS_UTF16) |
| 1415 void SplitStringAlongWhitespace(const string16& str, |
| 1416 std::vector<string16>* result) { |
| 1417 SplitStringAlongWhitespaceT(str, result); |
| 1418 } |
| 1419 #endif |
| 1420 |
| 1392 void SplitStringAlongWhitespace(const std::string& str, | 1421 void SplitStringAlongWhitespace(const std::string& str, |
| 1393 std::vector<std::string>* result) { | 1422 std::vector<std::string>* result) { |
| 1394 SplitStringAlongWhitespaceT(str, result); | 1423 SplitStringAlongWhitespaceT(str, result); |
| 1395 } | 1424 } |
| 1396 | 1425 |
| 1397 template<class StringType> | 1426 template<class StringType> |
| 1398 StringType DoReplaceStringPlaceholders(const StringType& format_string, | 1427 StringType DoReplaceStringPlaceholders(const StringType& format_string, |
| 1399 const std::vector<StringType>& subst, | 1428 const std::vector<StringType>& subst, |
| 1400 std::vector<size_t>* offsets) { | 1429 std::vector<size_t>* offsets) { |
| 1401 int substitutions = subst.size(); | 1430 int substitutions = subst.size(); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1778 // Each input byte creates two output hex characters. | 1807 // Each input byte creates two output hex characters. |
| 1779 std::string ret(size * 2, '\0'); | 1808 std::string ret(size * 2, '\0'); |
| 1780 | 1809 |
| 1781 for (size_t i = 0; i < size; ++i) { | 1810 for (size_t i = 0; i < size; ++i) { |
| 1782 char b = reinterpret_cast<const char*>(bytes)[i]; | 1811 char b = reinterpret_cast<const char*>(bytes)[i]; |
| 1783 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; | 1812 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; |
| 1784 ret[(i * 2) + 1] = kHexChars[b & 0xf]; | 1813 ret[(i * 2) + 1] = kHexChars[b & 0xf]; |
| 1785 } | 1814 } |
| 1786 return ret; | 1815 return ret; |
| 1787 } | 1816 } |
| OLD | NEW |