Interpret input starting with 0x as hex numbers in the default parser.

bool and string options remain unaffected.
This commit is contained in:
Philipp Claves 2017-03-09 11:51:50 +01:00
parent 1be5f10daf
commit b79f7cae36

View File

@ -404,10 +404,18 @@ namespace cxxopts
parse_value(const std::string& text, T& value) parse_value(const std::string& text, T& value)
{ {
std::istringstream is(text); std::istringstream is(text);
if (text.substr(0, 2) == "0x"){ //Hex number input
is.seekg(2);
if (!(is >> std::hex >> value))
{
throw argument_incorrect_type(text);
}
} else {
if (!(is >> value)) if (!(is >> value))
{ {
throw argument_incorrect_type(text); throw argument_incorrect_type(text);
} }
}
if (is.rdbuf()->in_avail() != 0) if (is.rdbuf()->in_avail() != 0)
{ {