library/src/utility/BP-StringUtilities.cc
// Tests to see if the provided string is a quoted string.
Tests to see if the provided string is a quoted string.
Tests to see if the provided string is a quoted string .
BP_STRING_QUOTE_CHECK_RESULTS BP_CheckIfBufferIsQuoted(char * buffer, size_t buffer_len)
{
	if(!buffer || !buffer_len)
		return BP_STRING_IS_UNDEFINED_OR_EMPTY;
	size_t number_of_single_quotes = 0;
	size_t number_of_double_quotes = 0;
	if(buffer[0] == '"')
		number_of_double_quotes++;
	if(buffer[buffer_len-1] == '"')
		number_of_double_quotes++;
	if(buffer[0] == '\'')
		number_of_single_quotes++;
	if(buffer[buffer_len-1] == '\'')
		number_of_single_quotes++;
	if
	(
			(number_of_single_quotes == 0) &&
			(number_of_double_quotes == 0)
	)
	{
		return BP_STRING_IS_NOT_QUOTED;
	}
	if
	(
		(number_of_single_quotes == 1) &&
		(number_of_double_quotes == 1)
	)
	{
		return BP_STRING_IS_MIXED_QUOTED_ERROR;
	}
	if
	(
			(number_of_single_quotes == 0) &&
			(number_of_double_quotes == 2)
	)
	{
		return BP_STRING_IS_DOUBLE_QUOTED;
	}
	if
	(
			(number_of_single_quotes == 2) &&
			(number_of_double_quotes == 0)
	)
	{
		return BP_STRING_IS_SINGLE_QUOTED;
	}
	if
	(
		(number_of_single_quotes == 1 && number_of_double_quotes == 0) ||
		(number_of_double_quotes == 1 && number_of_single_quotes == 0)
	)
	{
		return BP_STRING_IS_MISMATCHED_QUOTED;
	}
	return BP_STRING_RESULT_IS_UNDEFINED;
}
BP_STRING_QUOTE_CHECK_RESULTS BP_CheckIfBufferIsQuoted ( char * buffer , size_t buffer_len ) { if ( ! buffer || ! buffer_len ) return BP_STRING_IS_UNDEFINED_OR_EMPTY ; size_t number_of_single_quotes = 0 ; size_t number_of_double_quotes = 0 ; if ( buffer [ 0 ] == ' ' ) number_of_double_quotes ++ ; if ( buffer [ buffer_len - 1 ] == ' ' ) number_of_double_quotes ++ ; if ( buffer [ 0 ] == ' \' ' ) number_of_single_quotes ++ ; if ( buffer [ buffer_len - 1 ] == ' \' ' ) number_of_single_quotes ++ ; if ( ( number_of_single_quotes == 0 ) && ( number_of_double_quotes == 0 ) ) { return BP_STRING_IS_NOT_QUOTED ; } if ( ( number_of_single_quotes == 1 ) && ( number_of_double_quotes == 1 ) ) { return BP_STRING_IS_MIXED_QUOTED_ERROR ; } if ( ( number_of_single_quotes == 0 ) && ( number_of_double_quotes == 2 ) ) { return BP_STRING_IS_DOUBLE_QUOTED ; } if ( ( number_of_single_quotes == 2 ) && ( number_of_double_quotes == 0 ) ) { return BP_STRING_IS_SINGLE_QUOTED ; } if ( ( number_of_single_quotes == 1 && number_of_double_quotes == 0 ) || ( number_of_double_quotes == 1 && number_of_single_quotes == 0 ) ) { return BP_STRING_IS_MISMATCHED_QUOTED ; } return BP_STRING_RESULT_IS_UNDEFINED ; }
Tests to see if the provided string is a quoted string.
Tests to see if the provided string is a quoted string .
// check buffer or buffer length // holds the number of single or double quotes found within the string // check double quotes first // check single quotes next // check to see if the string is not quoted // check for mixed quote error // check for double quote next // check for single quote next // check for mismatch now // return undefined result if we haven't found any other match