From 8e35f78ad1fca3da2e96a208cda8a6ca9aa88df4 Mon Sep 17 00:00:00 2001 From: Eddie James Date: Thu, 30 Jun 2022 11:29:46 -0500 Subject: [PATCH] Set input stream base 0 for prefix-dependent parsing In order to support hexadecimal and octal values by their prefix, set the input stream base to zero. --- include/flags.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/flags.h b/include/flags.h index 7dcd61b..c43465c 100644 --- a/include/flags.h +++ b/include/flags.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -95,7 +96,9 @@ template std::optional get(const argument_map& options, const std::string_view& option) { if (const auto view = get_value(options, option)) { - if (T value; std::istringstream(std::string(*view)) >> value) return value; + if (T value; + std::istringstream(std::string(*view)) >> std::setbase(0) >> value) + return value; } return std::nullopt; } @@ -140,7 +143,7 @@ std::optional get(const std::vector& positional_arguments, if (positional_index < positional_arguments.size()) { if (T value; std::istringstream( std::string(positional_arguments[positional_index])) >> - value) + std::setbase(0) >> value) return value; } return std::nullopt;