diff --git a/include/tclap/MultiArg.h b/include/tclap/MultiArg.h index e53c7e2..039a047 100644 --- a/include/tclap/MultiArg.h +++ b/include/tclap/MultiArg.h @@ -182,6 +182,7 @@ bool MultiArg::processArg(int *i, vector& args) else _extractValue( value ); + _checkWithVisitor(); return true; } else @@ -196,13 +197,28 @@ void MultiArg::_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::_extractValue( const string& val ) { _values.push_back(val); - - _checkWithVisitor(); } /** diff --git a/include/tclap/ValueArg.h b/include/tclap/ValueArg.h index c1fd5cd..725bf9c 100644 --- a/include/tclap/ValueArg.h +++ b/include/tclap/ValueArg.h @@ -220,9 +220,25 @@ template void ValueArg::_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() ) ); + } /**