| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef BASE_STRING_NUMBER_CONVERSIONS_H_ | 5 #ifndef BASE_STRING_NUMBER_CONVERSIONS_H_ |
| 6 #define BASE_STRING_NUMBER_CONVERSIONS_H_ | 6 #define BASE_STRING_NUMBER_CONVERSIONS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 // Returns a hex string representation of a binary buffer. The returned hex | 87 // Returns a hex string representation of a binary buffer. The returned hex |
| 88 // string will be in upper case. This function does not check if |size| is | 88 // string will be in upper case. This function does not check if |size| is |
| 89 // within reasonable limits since it's written with trusted data in mind. If | 89 // within reasonable limits since it's written with trusted data in mind. If |
| 90 // you suspect that the data you want to format might be large, the absolute | 90 // you suspect that the data you want to format might be large, the absolute |
| 91 // max size for |size| should be is | 91 // max size for |size| should be is |
| 92 // std::numeric_limits<size_t>::max() / 2 | 92 // std::numeric_limits<size_t>::max() / 2 |
| 93 BASE_EXPORT std::string HexEncode(const void* bytes, size_t size); | 93 BASE_EXPORT std::string HexEncode(const void* bytes, size_t size); |
| 94 | 94 |
| 95 // Best effort conversion, see StringToInt above for restrictions. | 95 // Best effort conversion, see StringToInt above for restrictions. |
| 96 // Will only successful parse hex values that will fit into |output|, i.e. |
| 97 // -0x80000000 < |input| < 0x7FFFFFFF. |
| 96 BASE_EXPORT bool HexStringToInt(const StringPiece& input, int* output); | 98 BASE_EXPORT bool HexStringToInt(const StringPiece& input, int* output); |
| 97 | 99 |
| 100 // Best effort conversion, see StringToInt above for restrictions. |
| 101 // Will only successful parse hex values that will fit into |output|, i.e. |
| 102 // -0x8000000000000000 < |input| < 0x7FFFFFFFFFFFFFFF. |
| 103 BASE_EXPORT bool HexStringToInt64(const StringPiece& input, int64* output); |
| 104 |
| 98 // Similar to the previous functions, except that output is a vector of bytes. | 105 // Similar to the previous functions, except that output is a vector of bytes. |
| 99 // |*output| will contain as many bytes as were successfully parsed prior to the | 106 // |*output| will contain as many bytes as were successfully parsed prior to the |
| 100 // error. There is no overflow, but input.size() must be evenly divisible by 2. | 107 // error. There is no overflow, but input.size() must be evenly divisible by 2. |
| 101 // Leading 0x or +/- are not allowed. | 108 // Leading 0x or +/- are not allowed. |
| 102 BASE_EXPORT bool HexStringToBytes(const std::string& input, | 109 BASE_EXPORT bool HexStringToBytes(const std::string& input, |
| 103 std::vector<uint8>* output); | 110 std::vector<uint8>* output); |
| 104 | 111 |
| 105 } // namespace base | 112 } // namespace base |
| 106 | 113 |
| 107 #endif // BASE_STRING_NUMBER_CONVERSIONS_H_ | 114 #endif // BASE_STRING_NUMBER_CONVERSIONS_H_ |
| 108 | 115 |
| OLD | NEW |