Chromium Code Reviews| 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 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1503 int rstr_len = (max_len - 3) / 2; | 1503 int rstr_len = (max_len - 3) / 2; |
| 1504 int lstr_len = rstr_len + ((max_len - 3) % 2); | 1504 int lstr_len = rstr_len + ((max_len - 3) % 2); |
| 1505 output->assign(input.substr(0, lstr_len) + L"..." + | 1505 output->assign(input.substr(0, lstr_len) + L"..." + |
| 1506 input.substr(input.length() - rstr_len)); | 1506 input.substr(input.length() - rstr_len)); |
| 1507 break; | 1507 break; |
| 1508 } | 1508 } |
| 1509 } | 1509 } |
| 1510 | 1510 |
| 1511 return true; | 1511 return true; |
| 1512 } | 1512 } |
| 1513 | |
| 1514 std::string HexEncode(const void* bytes, size_t size) { | |
| 1515 static const char kHexChars[] = { | |
|
Dean McNamee
2009/01/22 11:22:04
Could you use "0123456789ABCDEF" instead?
| |
| 1516 '0', '1', '2', '3', '4', '5', '6', '7', | |
| 1517 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; | |
| 1518 | |
| 1519 if (size == 0) | |
| 1520 return std::string(); | |
| 1521 | |
| 1522 std::string ret; | |
|
Dean McNamee
2009/01/22 11:22:04
Why not:
std::string ret(size * 2, '\0'); or some
| |
| 1523 // For each byte, we print two characters. | |
| 1524 ret.resize(size * 2); | |
| 1525 | |
| 1526 const unsigned char* pos = reinterpret_cast<const unsigned char*>(bytes); | |
| 1527 const unsigned char* end = pos + size; | |
| 1528 std::string::iterator write = ret.begin(); | |
| 1529 while (pos < end) { | |
| 1530 unsigned char b = *pos; | |
| 1531 pos++; | |
| 1532 | |
| 1533 write[0] = kHexChars[(b >> 4) & 0xf]; | |
|
Dean McNamee
2009/01/22 11:22:04
I find write[0] strange if you're treating it like
| |
| 1534 write++; | |
| 1535 | |
| 1536 write[0] = kHexChars[b & 0xf]; | |
| 1537 write++; | |
| 1538 } | |
| 1539 | |
| 1540 return ret; | |
| 1541 } | |
| OLD | NEW |