Exemplo n.º 1
0
//++ ------------------------------------------------------------------------------------
// Details:	Parse the command's argument options string and try to extract all the words
//			between quotes then 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::ValidateQuotedText( CMICmdArgContext & vrwArgContext )
{
	// CODETAG_QUOTEDTEXT_SIMILAR_CODE
	const CMIUtilString strOptions = vrwArgContext.GetArgsLeftToParse();
	const MIchar cQuote = '"';
	const MIint nPos = strOptions.find( cQuote );
	if( nPos == (MIint) std::string::npos )
		return ValidateSingleText( vrwArgContext );

	// Is one and only quote at end of the string
	if( nPos == (MIint)(strOptions.length() - 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.find( cQuote, nPos + 1 );
	if( nPos2 == (MIint) std::string::npos )
		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;
}
Exemplo n.º 2
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 );
}
Exemplo n.º 3
0
//++ ------------------------------------------------------------------------------------
// 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;
}