inline int QtMultiArg::process( QtArgCmdLineContext & context ) { if( isWithValue() ) { ++m_count; return QtArg::process( context ); } else { bool ok = false; int intValue = 0; if( !context.atEnd() ) { const QString value = context.next(); intValue = value.toInt( &ok ); if( !ok ) context.putBack(); } if( ok ) m_count += intValue; else ++m_count; setPresent( true ); if( !isDefined() ) { setValue( QVariant( true ) ); setDefined( true ); } return 1; } return 0; }
inline void QtArgCmdLine::parse( bool parseAfterIgnoreRest ) { checkArgumentsCorrectness(); QString lastArgNameOrFlag; while( !m_context.atEnd() ) { const QString & arg = m_context.next(); QString name, nameWithoutDelims; { QString value; splitArgumentAndValue( arg, name, value ); nameWithoutDelims = removeDelimiters( name ); if( !value.isNull() ) m_context.prepend( value ); } // Argument. if( isArgument( arg ) ) { if( nameWithoutDelims.isEmpty() ) { if( !parseAfterIgnoreRest ) return; else continue; } QtArgIface * argument = findArgument( nameWithoutDelims ); lastArgNameOrFlag = name; if( argument != NULL ) { argument->process( m_context ); argument->visit( m_context ); argument->checkConstraint(); } else throw QtArgUnknownArgumentEx( QString::fromLatin1( "Unknown argument: %1" ) .arg( name ) ); } // Flag. else if( isFlag( arg ) ) { for( int i = 0, i_max = nameWithoutDelims.length() - 1; i <= i_max; ++i ) { QtArgIface * argument = findArgument( nameWithoutDelims[ i ] ); lastArgNameOrFlag = QString( m_delimiter ) + nameWithoutDelims[ i ]; if( i != i_max ) { QStringList dummyArgsList( nameWithoutDelims .right( nameWithoutDelims.length() - i - 1 ) ); QtArgCmdLineContext dummyContext( dummyArgsList ); if( argument->process( dummyContext ) ) { argument->visit( m_context ); argument->checkConstraint(); break; } } else argument->process( m_context ); argument->visit( m_context ); argument->checkConstraint(); } } // Something unexpected. else throw QtArgUnexpectedOptionEx( QString::fromLatin1( "Unexpected option: %1. " "Argument \"%2\" doesn't expect any values." ) .arg( name ).arg( lastArgNameOrFlag ) ); } checkMandatoryArguments(); }