library/src/utility/BP-StringUtilities.cc
// Simple check to ensure a string matches a UUID pattern.
Simple check to ensure a string matches a UUID pattern.
Simple check to ensure a string matches a UUID pattern .
BP_ERROR_T BP_StringIsUUID(char * str)
{
	if(!str)
		return ERR_FAILURE;
	if(strnlen(str, 40) != 36)
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(str, 36, BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	char *first_part  = &str[0];
	char *second_part = &str[9];
	char *third_part  = &str[14];
	char *fourth_part = &str[19];
	char *fifth_part  = &str[24];
	if
	(
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(first_part[0]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(first_part[1]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(first_part[2]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(first_part[3]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(first_part[4]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(first_part[5]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(first_part[6]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(first_part[7])
	)
	{
		return ERR_FAILURE;
	}
	if(first_part[8] != '-')
		return ERR_FAILURE;
	if
	(
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(second_part[0]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(second_part[1]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(second_part[2]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(second_part[3])
	)
	{
		return ERR_FAILURE;
	}
	if(second_part[4] != '-')
		return ERR_FAILURE;
	if
	(
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(third_part[0]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(third_part[1]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(third_part[2]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(third_part[3])
	)
	{
		return ERR_FAILURE;
	}
	if(third_part[4] != '-')
		return ERR_FAILURE;
	if
	(
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fourth_part[0]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fourth_part[1]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fourth_part[2]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fourth_part[3])
	)
	{
		return ERR_FAILURE;
	}
	if(fourth_part[4] != '-')
		return ERR_FAILURE;
	if
	(
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fifth_part[0]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fifth_part[1]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fifth_part[2]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fifth_part[3]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fifth_part[4]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fifth_part[5]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fifth_part[6]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fifth_part[7]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fifth_part[8]) ||
		!BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER(fifth_part[9])
	)
	{
		return ERR_FAILURE;
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_StringIsUUID ( char * str ) { if ( ! str ) return ERR_FAILURE ; if ( strnlen ( str , 40 ) != 36 ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( str , 36 , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; char * first_part = & str [ 0 ] ; char * second_part = & str [ 9 ] ; char * third_part = & str [ 14 ] ; char * fourth_part = & str [ 19 ] ; char * fifth_part = & str [ 24 ] ; if ( ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( first_part [ 0 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( first_part [ 1 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( first_part [ 2 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( first_part [ 3 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( first_part [ 4 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( first_part [ 5 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( first_part [ 6 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( first_part [ 7 ] ) ) { return ERR_FAILURE ; } if ( first_part [ 8 ] != ' ' ) return ERR_FAILURE ; if ( ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( second_part [ 0 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( second_part [ 1 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( second_part [ 2 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( second_part [ 3 ] ) ) { return ERR_FAILURE ; } if ( second_part [ 4 ] != ' ' ) return ERR_FAILURE ; if ( ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( third_part [ 0 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( third_part [ 1 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( third_part [ 2 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( third_part [ 3 ] ) ) { return ERR_FAILURE ; } if ( third_part [ 4 ] != ' ' ) return ERR_FAILURE ; if ( ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fourth_part [ 0 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fourth_part [ 1 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fourth_part [ 2 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fourth_part [ 3 ] ) ) { return ERR_FAILURE ; } if ( fourth_part [ 4 ] != ' ' ) return ERR_FAILURE ; if ( ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fifth_part [ 0 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fifth_part [ 1 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fifth_part [ 2 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fifth_part [ 3 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fifth_part [ 4 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fifth_part [ 5 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fifth_part [ 6 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fifth_part [ 7 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fifth_part [ 8 ] ) || ! BP_IS_VALID_ASCII_CHAR_OR_DIGIT_LOWER ( fifth_part [ 9 ] ) ) { return ERR_FAILURE ; } return ERR_SUCCESS ; }
Simple check to ensure a string matches a UUID pattern.
Simple check to ensure a string matches a UUID pattern .
// ensure we have a string // ensure the string is 36 bytes long // ensure string is reasonable/printable // set parts from indexable positions // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Checks on First Part %%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // check first part first (fast branch math via macros) // check first part joiner // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Checks on Second Part %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // check second part first (fast branch math via macros) // check second part joiner // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Checks on Third Part %%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // check third part first (fast branch math via macros) // check third part joiner // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Checks on Fourth Part %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // check third part fourth (fast branch math via macros) // check fourth part joiner // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Checks on Fifth Part %%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // check third part fifth (fast branch math via macros) // return indicating we have a uuid match