Ejemplo n.º 1
0
//++ ------------------------------------------------------------------------------------
// Details: Examine the string and determine if it is a valid string type argument.
// Type:    Method.
// Args:    vrTxt   - (R) Some text.
// Return:  bool -  True = yes valid arg, false = no.
// Throws:  None.
//--
bool
CMICmdArgValListOfN::IsListOfN(const CMIUtilString &vrTxt) const
{
    CMIUtilString::VecString_t vecOptions;
    if ((m_eArgType == eArgValType_StringQuoted) || (m_eArgType == eArgValType_StringQuotedNumber) ||
        (m_eArgType == eArgValType_StringQuotedNumberPath) || (m_eArgType == eArgValType_StringAnything))
    {
        if (vrTxt.SplitConsiderQuotes(" ", vecOptions) == 0)
            return false;
    }
    else if (vrTxt.Split(" ", vecOptions) == 0)
        return false;

    CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
    while (it != vecOptions.end())
    {
        const CMIUtilString &rOption = *it;
        if (!IsExpectedCorrectType(rOption, m_eArgType))
            break;

        // Next
        ++it;
    }

    return true;
}
Ejemplo n.º 2
0
//++ ------------------------------------------------------------------------------------
// Details:	Parse the text following *this argument and extract the options the values of
//			CMICmdArgValListBase::m_eArgType forming argument objects for each of those
//			options extracted.
// Type:	Method.
// Args:	vrwTxt		- (RW)	The command's argument options string.
//			nArgIndex	- (R)	The Nth arg position in argument context from the left.
// Return:	MIstatus::success - Functional succeeded.
//			MIstatus::failure - Functional failed.
// Throws:	None.
//--
bool CMICmdArgValOptionLong::ExtractExpectedOptions( CMICmdArgContext & vrwTxt, const MIuint nArgIndex ) 
{
	CMIUtilString::VecString_t vecOptions;
	MIuint nOptionsPresent = 0;
	if( (m_eExpectingOptionType != eArgValType_StringQuoted) && 
		(m_eExpectingOptionType != eArgValType_StringQuotedNumber) &&
		(m_eExpectingOptionType != eArgValType_StringQuotedNumberPath) )
		nOptionsPresent = vrwTxt.GetArgsLeftToParse().Split( " ", vecOptions );
	else
		nOptionsPresent = vrwTxt.GetArgsLeftToParse().SplitConsiderQuotes( " ", vecOptions );
	if( nOptionsPresent == 0 )
		return MIstatus::failure;

	MIuint nArgIndexCnt = 0;
	MIuint nTypeCnt = 0;
	MIuint nTypeCnt2 = 0;
	MIuint nFoundNOptionsCnt = 0;
	CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
	while( it != vecOptions.end() )
	{
		// Move to the Nth argument position from left before do validation/checking
		if( nArgIndexCnt++ == nArgIndex )
		{
			nTypeCnt++;
			const CMIUtilString & rOption( *it ); 
			if( IsExpectedCorrectType( rOption, m_eExpectingOptionType ) )
			{
				nTypeCnt2++;
				CMICmdArgValBase * pOptionObj = CreationObj( rOption, m_eExpectingOptionType );
				if( (pOptionObj != nullptr) && vrwTxt.RemoveArgAtPos( rOption, nArgIndex ) )
				{
					nFoundNOptionsCnt++;
					m_vecArgsExpected.push_back( pOptionObj );
				}
			}

			// Is the sequence 'options' of same type broken. Expecting the same type until the
			// next argument.
			if( nTypeCnt != nTypeCnt2 )
				return MIstatus::failure;

			if( nFoundNOptionsCnt == m_nExpectingNOptions )
				return MIstatus::success;
		}

		// Next
		++it;
	}
	if( nFoundNOptionsCnt != m_nExpectingNOptions )
		return MIstatus::failure;

	return MIstatus::success;
}