mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-07 19:29:07 -04:00
fixed error reading incorrect extra values in an arg
This commit is contained in:
parent
2e935f495e
commit
594b71d526
@ -182,6 +182,7 @@ bool MultiArg<T>::processArg(int *i, vector<string>& args)
|
||||
else
|
||||
_extractValue( value );
|
||||
|
||||
_checkWithVisitor();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -196,13 +197,28 @@ void MultiArg<T>::_extractValue( const string& val )
|
||||
{
|
||||
T temp;
|
||||
istringstream is(val);
|
||||
is >> temp;
|
||||
if ( is.fail() )
|
||||
throw( ArgException("Couldn't read argument value!", toString()));
|
||||
|
||||
int valuesRead = 0;
|
||||
while ( is.good() )
|
||||
{
|
||||
if ( is.peek() != EOF )
|
||||
is >> temp;
|
||||
else
|
||||
break;
|
||||
|
||||
valuesRead++;
|
||||
}
|
||||
|
||||
if ( is.fail() )
|
||||
throw( ArgException("Couldn't read argument value from string '" +
|
||||
val + "'", toString() ) );
|
||||
|
||||
if ( valuesRead > 1 )
|
||||
throw( ArgException("More than one valid value parsed from string '" +
|
||||
val + "'", toString() ) );
|
||||
|
||||
_values.push_back(temp);
|
||||
|
||||
_checkWithVisitor();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -213,8 +229,6 @@ template<>
|
||||
void MultiArg<string>::_extractValue( const string& val )
|
||||
{
|
||||
_values.push_back(val);
|
||||
|
||||
_checkWithVisitor();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -220,9 +220,25 @@ template<class T>
|
||||
void ValueArg<T>::_extractValue( const string& val )
|
||||
{
|
||||
istringstream is(val);
|
||||
is >> _value;
|
||||
|
||||
int valuesRead = 0;
|
||||
while ( is.good() )
|
||||
{
|
||||
if ( is.peek() != EOF )
|
||||
is >> _value;
|
||||
else
|
||||
break;
|
||||
valuesRead++;
|
||||
}
|
||||
|
||||
if ( is.fail() )
|
||||
throw( ArgException("Couldn't read argument value!", toString() ) );
|
||||
throw( ArgException("Couldn't read argument value from string '" +
|
||||
val + "'", toString() ) );
|
||||
|
||||
if ( valuesRead > 1 )
|
||||
throw( ArgException("More than one valid value parsed from string '" +
|
||||
val + "'", toString() ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user