-// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/dynamic_bitset.hpp>
+#include <sstream>
using namespace std;
using namespace isc::util;
result = boost::lexical_cast<int64_t>(value_str);
} catch (const boost::bad_lexical_cast&) {
- isc_throw(BadDataTypeCast, "unable to convert the value '"
- << value_str << "' to integer data type");
+ // boost::lexical_cast does not handle hexadecimal
+ // but stringstream does so do it the hard way.
+ std::stringstream ss;
+ ss << std::hex << value_str;
+ ss >> result;
+ if (ss.fail() || !ss.eof()) {
+ isc_throw(BadDataTypeCast, "unable to convert the value '"
+ << value_str << "' to integer data type");
+ }
}
// Perform range checks.
if (OptionDataTypeTraits<T>::integer_type) {
-// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
/// This function performs lexical cast of a string value to integer
/// value and checks if the resulting value is within a range of a
/// target type. The target type should be one of the supported
- /// integer types.
+ /// integer types. Hexadecimal input is supported.
///
/// @param value_str input value given as string.
/// @tparam T target integer type for lexical cast.
OptionPtr option_v6;
std::vector<std::string> str_values;
str_values.push_back("123456");
- str_values.push_back("7");
+ // Try with hexadecimal
+ str_values.push_back("0x7");
str_values.push_back("256");
str_values.push_back("1111");