| 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 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 output->assign(input.substr(0, lstr_len) + L"..." + | 1527 output->assign(input.substr(0, lstr_len) + L"..." + |
| 1528 input.substr(input.length() - rstr_len)); | 1528 input.substr(input.length() - rstr_len)); |
| 1529 break; | 1529 break; |
| 1530 } | 1530 } |
| 1531 } | 1531 } |
| 1532 | 1532 |
| 1533 return true; | 1533 return true; |
| 1534 } | 1534 } |
| 1535 | 1535 |
| 1536 std::string HexEncode(const void* bytes, size_t size) { | 1536 std::string HexEncode(const void* bytes, size_t size) { |
| 1537 static const char kHexChars[] = { | 1537 static const char kHexChars[] = "0123456789ABCDEF"; |
| 1538 '0', '1', '2', '3', '4', '5', '6', '7', | |
| 1539 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; | |
| 1540 | 1538 |
| 1541 if (size == 0) | 1539 // Each input byte creates two output hex characters. |
| 1542 return std::string(); | 1540 std::string ret(size * 2, '\0'); |
| 1543 | 1541 |
| 1544 std::string ret; | 1542 for (size_t i = 0; i < size; ++i) { |
| 1545 // For each byte, we print two characters. | 1543 char b = reinterpret_cast<const char*>(bytes)[i]; |
| 1546 ret.resize(size * 2); | 1544 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; |
| 1547 | 1545 ret[(i * 2) + 1] = kHexChars[b & 0xf]; |
| 1548 const unsigned char* pos = reinterpret_cast<const unsigned char*>(bytes); | |
| 1549 const unsigned char* end = pos + size; | |
| 1550 std::string::iterator write = ret.begin(); | |
| 1551 while (pos < end) { | |
| 1552 unsigned char b = *pos; | |
| 1553 pos++; | |
| 1554 | |
| 1555 write[0] = kHexChars[(b >> 4) & 0xf]; | |
| 1556 write++; | |
| 1557 | |
| 1558 write[0] = kHexChars[b & 0xf]; | |
| 1559 write++; | |
| 1560 } | 1546 } |
| 1561 | |
| 1562 return ret; | 1547 return ret; |
| 1563 } | 1548 } |
| OLD | NEW |