| 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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 bool trim_sequences_with_line_breaks) { | 495 bool trim_sequences_with_line_breaks) { |
| 496 return CollapseWhitespaceT(text, trim_sequences_with_line_breaks); | 496 return CollapseWhitespaceT(text, trim_sequences_with_line_breaks); |
| 497 } | 497 } |
| 498 | 498 |
| 499 std::string CollapseWhitespaceASCII(const std::string& text, | 499 std::string CollapseWhitespaceASCII(const std::string& text, |
| 500 bool trim_sequences_with_line_breaks) { | 500 bool trim_sequences_with_line_breaks) { |
| 501 return CollapseWhitespaceT(text, trim_sequences_with_line_breaks); | 501 return CollapseWhitespaceT(text, trim_sequences_with_line_breaks); |
| 502 } | 502 } |
| 503 | 503 |
| 504 std::string WideToASCII(const std::wstring& wide) { | 504 std::string WideToASCII(const std::wstring& wide) { |
| 505 DCHECK(IsStringASCII(wide)); | 505 DCHECK(IsStringASCII(wide)) << wide; |
| 506 return std::string(wide.begin(), wide.end()); | 506 return std::string(wide.begin(), wide.end()); |
| 507 } | 507 } |
| 508 | 508 |
| 509 std::wstring ASCIIToWide(const StringPiece& ascii) { | 509 std::wstring ASCIIToWide(const StringPiece& ascii) { |
| 510 DCHECK(IsStringASCII(ascii)); | 510 DCHECK(IsStringASCII(ascii)) << ascii; |
| 511 return std::wstring(ascii.begin(), ascii.end()); | 511 return std::wstring(ascii.begin(), ascii.end()); |
| 512 } | 512 } |
| 513 | 513 |
| 514 std::string UTF16ToASCII(const string16& utf16) { | 514 std::string UTF16ToASCII(const string16& utf16) { |
| 515 DCHECK(IsStringASCII(utf16)); | 515 DCHECK(IsStringASCII(utf16)) << utf16; |
| 516 return std::string(utf16.begin(), utf16.end()); | 516 return std::string(utf16.begin(), utf16.end()); |
| 517 } | 517 } |
| 518 | 518 |
| 519 string16 ASCIIToUTF16(const StringPiece& ascii) { | 519 string16 ASCIIToUTF16(const StringPiece& ascii) { |
| 520 DCHECK(IsStringASCII(ascii)); | 520 DCHECK(IsStringASCII(ascii)) << ascii; |
| 521 return string16(ascii.begin(), ascii.end()); | 521 return string16(ascii.begin(), ascii.end()); |
| 522 } | 522 } |
| 523 | 523 |
| 524 // Latin1 is just the low range of Unicode, so we can copy directly to convert. | 524 // Latin1 is just the low range of Unicode, so we can copy directly to convert. |
| 525 bool WideToLatin1(const std::wstring& wide, std::string* latin1) { | 525 bool WideToLatin1(const std::wstring& wide, std::string* latin1) { |
| 526 std::string output; | 526 std::string output; |
| 527 output.resize(wide.size()); | 527 output.resize(wide.size()); |
| 528 latin1->clear(); | 528 latin1->clear(); |
| 529 for (size_t i = 0; i < wide.size(); i++) { | 529 for (size_t i = 0; i < wide.size(); i++) { |
| 530 if (wide[i] > 255) | 530 if (wide[i] > 255) |
| (...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1665 // Each input byte creates two output hex characters. | 1665 // Each input byte creates two output hex characters. |
| 1666 std::string ret(size * 2, '\0'); | 1666 std::string ret(size * 2, '\0'); |
| 1667 | 1667 |
| 1668 for (size_t i = 0; i < size; ++i) { | 1668 for (size_t i = 0; i < size; ++i) { |
| 1669 char b = reinterpret_cast<const char*>(bytes)[i]; | 1669 char b = reinterpret_cast<const char*>(bytes)[i]; |
| 1670 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; | 1670 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; |
| 1671 ret[(i * 2) + 1] = kHexChars[b & 0xf]; | 1671 ret[(i * 2) + 1] = kHexChars[b & 0xf]; |
| 1672 } | 1672 } |
| 1673 return ret; | 1673 return ret; |
| 1674 } | 1674 } |
| OLD | NEW |