示例#1
0
//++ ------------------------------------------------------------------------------------
// Details:	Parse the command's argument options string and try to extract the value *this
//			argument is looking for.
// Type:	Overridden.
// Args:	vrwArgContext	- (RW) The command's argument options string.
// Return:	MIstatus::success - Functional succeeded.
//			MIstatus::failure - Functional failed.
// Throws:	None.
//--
bool CMICmdArgValString::Validate( CMICmdArgContext & vrwArgContext )
{
	if( vrwArgContext.IsEmpty() )
		return MIstatus::success;

	if( m_bHandleQuotedString )
		return ValidateQuotedText( vrwArgContext );

	return ValidateSingleText( vrwArgContext );
}
示例#2
0
//++ ------------------------------------------------------------------------------------
// 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;
}