Inside:
inline bool parser::is_number(std::string const& arg) const
{
std::istringstream istr(arg);
double number;
istr >> number;
return !(istr.fail() || istr.bad());
}
stream extraction succeeds when it can parse a numeric prefix. It doesn't require the entire string to be numeric.
For example:
-1abc -> parses numeric prefix -1;
-1.2.3 -> parses numeric prefix -1.2.
and is_number() returns true. Then
inline bool parser::is_option(std::string const& arg) const
{
assert(0 != arg.size());
if (is_number(arg))
return false;
...
returns false, causing these arguments to be stored as positional values:
const char* argv[] = { "-1abc" };
argh::parser cmdl(1, argv);
Actual:
cmdl.pos_args().size() == 1
cmdl.flags().empty()
Expected:
This can also alter subsequent parsing. Given a registered parameter --output -1abc, -1abc may be consumed as output value instead of being recognised as another option.
Inside:
stream extraction succeeds when it can parse a numeric prefix. It doesn't require the entire string to be numeric.
For example:
-1abc-> parses numeric prefix-1;-1.2.3-> parses numeric prefix-1.2.and
is_number()returnstrue. Thenreturns
false, causing these arguments to be stored as positional values:Actual:
cmdl.pos_args().size() == 1 cmdl.flags().empty()Expected:
This can also alter subsequent parsing. Given a registered parameter
--output -1abc,-1abcmay be consumed as output value instead of being recognised as another option.