| 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 #include "base/strings/string_number_conversions.h" | 5 #include "base/strings/string_number_conversions.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <wctype.h> | 10 #include <wctype.h> |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 // Utility to convert a character to a digit in a given base | 97 // Utility to convert a character to a digit in a given base |
| 98 template<typename CHAR, int BASE, bool BASE_LTE_10> class BaseCharToDigit { | 98 template<typename CHAR, int BASE, bool BASE_LTE_10> class BaseCharToDigit { |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 // Faster specialization for bases <= 10 | 101 // Faster specialization for bases <= 10 |
| 102 template<typename CHAR, int BASE> class BaseCharToDigit<CHAR, BASE, true> { | 102 template<typename CHAR, int BASE> class BaseCharToDigit<CHAR, BASE, true> { |
| 103 public: | 103 public: |
| 104 static bool Convert(CHAR c, uint8* digit) { | 104 static bool Convert(CHAR c, uint8* digit) { |
| 105 if (c >= '0' && c < '0' + BASE) { | 105 if (c >= '0' && c < '0' + BASE) { |
| 106 *digit = c - '0'; | 106 *digit = static_cast<uint8>(c - '0'); |
| 107 return true; | 107 return true; |
| 108 } | 108 } |
| 109 return false; | 109 return false; |
| 110 } | 110 } |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 // Specialization for bases where 10 < base <= 36 | 113 // Specialization for bases where 10 < base <= 36 |
| 114 template<typename CHAR, int BASE> class BaseCharToDigit<CHAR, BASE, false> { | 114 template<typename CHAR, int BASE> class BaseCharToDigit<CHAR, BASE, false> { |
| 115 public: | 115 public: |
| 116 static bool Convert(CHAR c, uint8* digit) { | 116 static bool Convert(CHAR c, uint8* digit) { |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 bool HexStringToUInt64(const StringPiece& input, uint64* output) { | 520 bool HexStringToUInt64(const StringPiece& input, uint64* output) { |
| 521 return IteratorRangeToNumber<HexIteratorRangeToUInt64Traits>::Invoke( | 521 return IteratorRangeToNumber<HexIteratorRangeToUInt64Traits>::Invoke( |
| 522 input.begin(), input.end(), output); | 522 input.begin(), input.end(), output); |
| 523 } | 523 } |
| 524 | 524 |
| 525 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { | 525 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { |
| 526 return HexStringToBytesT(input, output); | 526 return HexStringToBytesT(input, output); |
| 527 } | 527 } |
| 528 | 528 |
| 529 } // namespace base | 529 } // namespace base |
| OLD | NEW |