//++ ------------------------------------------------------------------------------------ // Details: Parse the command's argument options string and try to extract the value *this // argument is looking for. // Type: Overridden. // Args: vwArgContext - (RW) The command's argument options string. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. // Throws: None. //-- bool CMICmdArgValThreadGrp::Validate( CMICmdArgContext & vwArgContext ) { if( vwArgContext.IsEmpty() ) return MIstatus::success; if( vwArgContext.GetNumberArgsPresent() == 1 ) { const CMIUtilString & rArg( vwArgContext.GetArgsLeftToParse() ); if( IsArgThreadGrp( rArg ) && ExtractNumber( rArg ) ) { m_bFound = true; m_bValid = true; m_argValue = GetNumber(); vwArgContext.RemoveArg( rArg ); return MIstatus::success; } else return MIstatus::failure; } // More than one option... const CMIUtilString::VecString_t vecOptions( vwArgContext.GetArgs() ); CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); while( it != vecOptions.end() ) { const CMIUtilString & rArg( *it ); if( IsArgThreadGrp( rArg ) && ExtractNumber( rArg ) ) { m_bFound = true; if( vwArgContext.RemoveArg( rArg ) ) { m_bValid = true; m_argValue = GetNumber(); return MIstatus::success; } else return MIstatus::failure; } // Next ++it; } return MIstatus::failure; }
//++ ------------------------------------------------------------------------------------ // Details: Parse the command's argument options string and try to extract only the next // word delimited by the next space. // Type: Method. // Args: vrwArgContext - (RW) The command's argument options string. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. // Throws: None. //-- bool CMICmdArgValString::ValidateSingleText( CMICmdArgContext & vrwArgContext ) { if( vrwArgContext.GetNumberArgsPresent() == 1 ) { const CMIUtilString & rArg( vrwArgContext.GetArgsLeftToParse() ); if( IsStringArg( rArg ) ) { m_bFound = true; m_bValid = true; m_argValue = rArg; vrwArgContext.RemoveArg( rArg ); return MIstatus::success; } else return MIstatus::failure; } // More than one option... const CMIUtilString::VecString_t vecOptions( vrwArgContext.GetArgs() ); CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); while( it != vecOptions.end() ) { const CMIUtilString & rArg( *it ); if( IsStringArg( rArg ) ) { m_bFound = true; if( vrwArgContext.RemoveArg( rArg ) ) { m_bValid = true; m_argValue = rArg; return MIstatus::success; } else return MIstatus::failure; } // Next ++it; } return MIstatus::failure; }
//++ // Details: Parse the command's argument options string and try to extract the // value *this // argument is looking for. // Type: Overridden. // Args: vwArgContext - (RW) The command's argument options string. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. // Throws: None. //-- bool CMICmdArgValPrintValues::Validate(CMICmdArgContext &vwArgContext) { if (vwArgContext.IsEmpty()) return m_bMandatory ? MIstatus::failure : MIstatus::success; const CMIUtilString strArg(vwArgContext.GetArgs()[0]); if (IsArgPrintValues(strArg) && ExtractPrintValues(strArg)) { m_bFound = true; m_bValid = true; m_argValue = GetPrintValues(); vwArgContext.RemoveArg(strArg); return MIstatus::success; } return MIstatus::failure; }
//++ ------------------------------------------------------------------------------------ // Details: Parse the command's argument options string and try to extract all the words // between quotes then delimited by the next space. If there any string format // characters '\\' used to embed quotes these are ignored i.e. "\\\"%5d\\\"" // becomes "%5d". Can fall through to ValidateQuotedText(). // Type: Method. // Args: vrwArgContext - (RW) The command's argument options string. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. // Throws: None. //-- bool CMICmdArgValString::ValidateQuotedTextEmbedded( CMICmdArgContext & vrwArgContext ) { // CODETAG_QUOTEDTEXT_SIMILAR_CODE CMIUtilString strOptions = vrwArgContext.GetArgsLeftToParse(); const MIchar cBckSlash = '\\'; const MIint nPos = strOptions.find( cBckSlash ); if( nPos == (MIint) std::string::npos ) return ValidateQuotedText( vrwArgContext ); // Back slash must be the first character in the string or be preceeded by a space // or '\\' const MIchar cSpace = ' '; if( (nPos > 0) && (strOptions[ nPos - 1 ] != cSpace) ) return MIstatus::failure; // Need to find the other back slash const MIint nPos2 = strOptions.rfind( cBckSlash ); if( nPos2 == (MIint) std::string::npos ) return MIstatus::failure; // Make sure not same back slash, need two slashs if( nPos == nPos2 ) return MIstatus::failure; // Look for the two quotes const MIint nLen = strOptions.length(); const MIchar cQuote = '"'; const MIint nPosQuote1 = nPos + 1; const MIint nPosQuote2 = (nPos2 < nLen) ? nPos2 + 1 : nPos2; if( (nPosQuote1 != nPosQuote2) && (strOptions[ nPosQuote1 ] != cQuote) && (strOptions[ nPosQuote2 ] != cQuote) ) return MIstatus::failure; // Extract quoted text const CMIUtilString strQuotedTxt = strOptions.substr( nPos, nPosQuote2 - nPos + 1 ).c_str(); if( vrwArgContext.RemoveArg( strQuotedTxt ) ) { m_bFound = true; m_bValid = true; m_argValue = strQuotedTxt; return MIstatus::success; } return MIstatus::failure; }
//++ ------------------------------------------------------------------------------------ // Details: Parse the command's argument options string and try to extract all the words // between quotes then delimited by the next space. Can fall through to // ValidateSingleText() or ValidateQuotedQuotedTextEmbedded(). // Type: Method. // Args: vrwArgContext - (RW) The command's argument options string. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. // Throws: None. //-- bool CMICmdArgValString::ValidateQuotedText( CMICmdArgContext & vrwArgContext ) { // CODETAG_QUOTEDTEXT_SIMILAR_CODE CMIUtilString strOptions = vrwArgContext.GetArgsLeftToParse(); const MIchar cQuote = '"'; // Look for first quote of two MIint nPos = strOptions.find( cQuote ); if( nPos == (MIint) std::string::npos ) return ValidateSingleText( vrwArgContext ); // Is one and only quote at end of the string const MIint nLen = strOptions.length(); if( nPos == (MIint)(nLen - 1) ) return MIstatus::failure; // Quote must be the first character in the string or be preceeded by a space if( (nPos > 0) && (strOptions[ nPos - 1 ] != ' ') ) return MIstatus::failure; // Need to find the other quote const MIint nPos2 = strOptions.rfind( cQuote ); if( nPos2 == (MIint) std::string::npos ) return MIstatus::failure; // Is there quotes surrounding string formatting embedded quotes if( IsStringArgQuotedQuotedTextEmbedded( strOptions ) ) return ValidateQuotedQuotedTextEmbedded( vrwArgContext ); // Make sure not same back quote, need two quotes if( nPos == nPos2 ) return MIstatus::failure; // Extract quoted text const CMIUtilString strQuotedTxt = strOptions.substr( nPos, nPos2 - nPos + 1 ).c_str(); if( vrwArgContext.RemoveArg( strQuotedTxt ) ) { m_bFound = true; m_bValid = true; m_argValue = strOptions.substr( nPos + 1, nPos2 - nPos - 1 ).c_str(); return MIstatus::success; } return MIstatus::failure; }
//++ ------------------------------------------------------------------------------------ // Details: Parse the command's argument options string and try to extract the list of // arguments based on the argument object type to look for. // Type: Overridden. // Args: vwArgContext - (RW) The command's argument options string. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. // Throws: None. //-- bool CMICmdArgValListOfN::Validate( CMICmdArgContext & vwArgContext ) { if( m_eArgType >= eArgValType_count ) { m_eArgType = eArgValType_invalid; return MIstatus::failure; } if( vwArgContext.IsEmpty() ) return MIstatus::success; const CMIUtilString & rArg( vwArgContext.GetArgsLeftToParse() ); if( IsListOfN( rArg ) && CreateList( rArg ) ) { m_bFound = true; m_bValid = true; vwArgContext.RemoveArg( rArg ); return MIstatus::success; } else return MIstatus::failure; }
//++ ------------------------------------------------------------------------------------ // Details: Parse the command's argument options string and try to extract the long // argument *this argument type is looking for. // Type: Overridden. // Args: vwArgContext - (RW) The command's argument options string. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. // Throws: None. //-- bool CMICmdArgValOptionLong::Validate( CMICmdArgContext & vwArgContext ) { if( vwArgContext.IsEmpty() ) return MIstatus::success; if( vwArgContext.GetNumberArgsPresent() == 1 ) { const CMIUtilString & rArg( vwArgContext.GetArgsLeftToParse() ); if( IsArgLongOption( rArg ) && ArgNameMatch( rArg ) ) { m_bFound = true; if( !vwArgContext.RemoveArg( rArg ) ) return MIstatus::failure; if( m_nExpectingNOptions == 0 ) { m_bValid = true; return MIstatus::success; } m_bIsMissingOptions = true; return MIstatus::failure; } else return MIstatus::failure; } // More than one option... MIuint nArgIndex = 0; const CMIUtilString::VecString_t vecOptions( vwArgContext.GetArgs() ); CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); while( it != vecOptions.end() ) { const CMIUtilString & rArg( *it ); if( IsArgOptionCorrect( rArg ) && ArgNameMatch( rArg ) ) { m_bFound = true; if( !vwArgContext.RemoveArg( rArg ) ) return MIstatus::failure; if( m_nExpectingNOptions != 0 ) { if( ExtractExpectedOptions( vwArgContext, nArgIndex ) ) { m_bValid = true; return MIstatus::success; } m_bIsMissingOptions = true; return MIstatus::failure; } else { m_bValid = true; return MIstatus::success; } } // Next ++it; ++nArgIndex; } return MIstatus::failure; }