library/src/utility/BP-StringUtilities.cc
// string conforms to a basic URL
string conforms to a basic URL
string conforms to a basic URL
BP_ERROR_T BP_StringIsURL(char *str_value, BP_BOOL require_valid_tld_match)
{
	if(!str_value)
		return ERR_FAILURE;
	if(!strnlen(str_value, 1))
		return ERR_FAILURE;
	size_t len = bpstrlen(str_value);
	char * parsed_to_url = BP_ParseStringToURLPCRE(str_value, require_valid_tld_match);
	if(!parsed_to_url)
		return ERR_FAILURE;
	if(bpstrlen(parsed_to_url) != len)
	{
		free(parsed_to_url);
		return ERR_FAILURE;
	}
	if(memcmp(parsed_to_url, str_value, len) != 0)
	{
		free(parsed_to_url);
		return ERR_FAILURE;
	}
	free(parsed_to_url);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_StringIsURL ( char * str_value , BP_BOOL require_valid_tld_match ) { if ( ! str_value ) return ERR_FAILURE ; if ( ! strnlen ( str_value , 1 ) ) return ERR_FAILURE ; size_t len = bpstrlen ( str_value ) ; char * parsed_to_url = BP_ParseStringToURLPCRE ( str_value , require_valid_tld_match ) ; if ( ! parsed_to_url ) return ERR_FAILURE ; if ( bpstrlen ( parsed_to_url ) != len ) { free ( parsed_to_url ) ; return ERR_FAILURE ; } if ( memcmp ( parsed_to_url , str_value , len ) != 0 ) { free ( parsed_to_url ) ; return ERR_FAILURE ; } free ( parsed_to_url ) ; return ERR_SUCCESS ; }
string conforms to a basic URL
string conforms to a basic URL
// ensure we have a string value // ensure the value has length // determine string length // attempt to parse the value to a url // printf("\n Parsed to url?: %s - %s", str_value, parsed_to_url); // attempt to parse to url // if the parsed length is not matched to length, we know we // have unmatched data. // run a memory comparisson to ensure values match // destroy the parsed string // return indicating success