Index: base/string_number_conversions.cc |
diff --git a/base/string_number_conversions.cc b/base/string_number_conversions.cc |
index e80b6499f2e04c0787a48d08f87b306e9fc3e468..c55bbafff34ae70137167283e41146fd8da50597 100644 |
--- a/base/string_number_conversions.cc |
+++ b/base/string_number_conversions.cc |
@@ -302,9 +302,22 @@ class BaseHexIteratorRangeToIntTraits |
} |
}; |
+template<typename ITERATOR> |
+class BaseHexIteratorRangeToInt64Traits |
benquan
2012/12/15 02:48:59
Tests?
ahutter
2012/12/17 17:23:02
Covered by tests for HexStringToInt64.
|
+ : public BaseIteratorRangeToNumberTraits<ITERATOR, int64, 16> { |
+ public: |
+ // Allow parsing of 0xFFFFFFFFFFFFFFFF, which is technically an overflow |
+ static uint64 max() { |
+ return std::numeric_limits<uint64>::max(); |
+ } |
+}; |
+ |
typedef BaseHexIteratorRangeToIntTraits<StringPiece::const_iterator> |
HexIteratorRangeToIntTraits; |
+typedef BaseHexIteratorRangeToInt64Traits<StringPiece::const_iterator> |
+ HexIteratorRangeToInt64Traits; |
+ |
template<typename STR> |
bool HexStringToBytesT(const STR& input, std::vector<uint8>* output) { |
DCHECK_EQ(output->size(), 0u); |
@@ -481,6 +494,11 @@ bool HexStringToInt(const StringPiece& input, int* output) { |
input.begin(), input.end(), output); |
} |
+bool HexStringToInt64(const StringPiece& input, int64* output) { |
+ return IteratorRangeToNumber<HexIteratorRangeToInt64Traits>::Invoke( |
+ input.begin(), input.end(), output); |
+} |
+ |
bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { |
return HexStringToBytesT(input, output); |
} |