| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 template<typename ITERATOR> | 295 template<typename ITERATOR> |
| 296 class BaseHexIteratorRangeToIntTraits | 296 class BaseHexIteratorRangeToIntTraits |
| 297 : public BaseIteratorRangeToNumberTraits<ITERATOR, int, 16> { | 297 : public BaseIteratorRangeToNumberTraits<ITERATOR, int, 16> { |
| 298 }; | 298 }; |
| 299 | 299 |
| 300 template<typename ITERATOR> | 300 template<typename ITERATOR> |
| 301 class BaseHexIteratorRangeToInt64Traits | 301 class BaseHexIteratorRangeToInt64Traits |
| 302 : public BaseIteratorRangeToNumberTraits<ITERATOR, int64, 16> { | 302 : public BaseIteratorRangeToNumberTraits<ITERATOR, int64, 16> { |
| 303 }; | 303 }; |
| 304 | 304 |
| 305 template<typename ITERATOR> |
| 306 class BaseHexIteratorRangeToUInt64Traits |
| 307 : public BaseIteratorRangeToNumberTraits<ITERATOR, uint64, 16> { |
| 308 }; |
| 309 |
| 305 typedef BaseHexIteratorRangeToIntTraits<StringPiece::const_iterator> | 310 typedef BaseHexIteratorRangeToIntTraits<StringPiece::const_iterator> |
| 306 HexIteratorRangeToIntTraits; | 311 HexIteratorRangeToIntTraits; |
| 307 | 312 |
| 308 typedef BaseHexIteratorRangeToInt64Traits<StringPiece::const_iterator> | 313 typedef BaseHexIteratorRangeToInt64Traits<StringPiece::const_iterator> |
| 309 HexIteratorRangeToInt64Traits; | 314 HexIteratorRangeToInt64Traits; |
| 310 | 315 |
| 316 typedef BaseHexIteratorRangeToUInt64Traits<StringPiece::const_iterator> |
| 317 HexIteratorRangeToUInt64Traits; |
| 318 |
| 311 template<typename STR> | 319 template<typename STR> |
| 312 bool HexStringToBytesT(const STR& input, std::vector<uint8>* output) { | 320 bool HexStringToBytesT(const STR& input, std::vector<uint8>* output) { |
| 313 DCHECK_EQ(output->size(), 0u); | 321 DCHECK_EQ(output->size(), 0u); |
| 314 size_t count = input.size(); | 322 size_t count = input.size(); |
| 315 if (count == 0 || (count % 2) != 0) | 323 if (count == 0 || (count % 2) != 0) |
| 316 return false; | 324 return false; |
| 317 for (uintptr_t i = 0; i < count / 2; ++i) { | 325 for (uintptr_t i = 0; i < count / 2; ++i) { |
| 318 uint8 msb = 0; // most significant 4 bits | 326 uint8 msb = 0; // most significant 4 bits |
| 319 uint8 lsb = 0; // least significant 4 bits | 327 uint8 lsb = 0; // least significant 4 bits |
| 320 if (!CharToDigit<16>(input[i * 2], &msb) || | 328 if (!CharToDigit<16>(input[i * 2], &msb) || |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 bool HexStringToInt(const StringPiece& input, int* output) { | 492 bool HexStringToInt(const StringPiece& input, int* output) { |
| 485 return IteratorRangeToNumber<HexIteratorRangeToIntTraits>::Invoke( | 493 return IteratorRangeToNumber<HexIteratorRangeToIntTraits>::Invoke( |
| 486 input.begin(), input.end(), output); | 494 input.begin(), input.end(), output); |
| 487 } | 495 } |
| 488 | 496 |
| 489 bool HexStringToInt64(const StringPiece& input, int64* output) { | 497 bool HexStringToInt64(const StringPiece& input, int64* output) { |
| 490 return IteratorRangeToNumber<HexIteratorRangeToInt64Traits>::Invoke( | 498 return IteratorRangeToNumber<HexIteratorRangeToInt64Traits>::Invoke( |
| 491 input.begin(), input.end(), output); | 499 input.begin(), input.end(), output); |
| 492 } | 500 } |
| 493 | 501 |
| 502 bool HexStringToUInt64(const StringPiece& input, uint64* output) { |
| 503 return IteratorRangeToNumber<HexIteratorRangeToUInt64Traits>::Invoke( |
| 504 input.begin(), input.end(), output); |
| 505 } |
| 506 |
| 494 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { | 507 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { |
| 495 return HexStringToBytesT(input, output); | 508 return HexStringToBytesT(input, output); |
| 496 } | 509 } |
| 497 | 510 |
| 498 } // namespace base | 511 } // namespace base |
| OLD | NEW |