diff --git a/include/argparse.hpp b/include/argparse.hpp index 9a3878c..b14f4b1 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -964,6 +964,16 @@ namespace argparse virtual auto get_name_for_error() const -> std::string = 0; + static auto is_negative_number(std::string const & token) -> bool + { + auto num = double(); + if (from_string(token, num)) + { + return true; + } + return false; + } + private: ArgumentCommonImpl m_impl; }; @@ -1034,10 +1044,7 @@ namespace argparse { return true; } - auto iss = std::istringstream(token.m_token); - auto num = double(); - iss >> num; - if (!iss.fail() && (iss.eof() || iss.peek() == std::istringstream::traits_type::eof())) + if (is_negative_number(token.m_token)) { return true; } @@ -1412,10 +1419,7 @@ namespace argparse { return true; } - auto iss = std::istringstream(token.m_token); - auto num = double(); - iss >> num; - if (!iss.fail() && (iss.eof() || iss.peek() == std::istringstream::traits_type::eof())) + if (is_negative_number(token.m_token)) { return true; }