//++ ------------------------------------------------------------------------------------ // Details: Create list of argument objects each holding a value extract from the command // options line. // Type: Method. // Args: vrTxt - (R) Some options text. // Return: bool - True = yes valid arg, false = no. // Throws: None. //-- bool CMICmdArgValListOfN::CreateList(const CMIUtilString &vrTxt) { 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 MIstatus::failure; } else if (vrTxt.Split(" ", vecOptions) == 0) return MIstatus::failure; CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); while (it != vecOptions.end()) { const CMIUtilString &rOption = *it; CMICmdArgValBase *pOption = CreationObj(rOption, m_eArgType); if (pOption != nullptr) m_argValue.push_back(pOption); else return MIstatus::failure; // Next ++it; } return MIstatus::success; }
//++ ------------------------------------------------------------------------------------ // 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; }