From b79f7cae36fdc5e50019627c7af951d47936e2da Mon Sep 17 00:00:00 2001 From: Philipp Claves Date: Thu, 9 Mar 2017 11:51:50 +0100 Subject: [PATCH] Interpret input starting with 0x as hex numbers in the default parser. bool and string options remain unaffected. --- include/cxxopts.hpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index c33c06a..06b1896 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -404,9 +404,17 @@ namespace cxxopts parse_value(const std::string& text, T& value) { std::istringstream is(text); - if (!(is >> value)) - { - throw argument_incorrect_type(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)) + { + throw argument_incorrect_type(text); + } } if (is.rdbuf()->in_avail() != 0)