library/src/utility/BP-StringUtilities.cc
// parses a url to a base using pcre
parses a url to a base using pcre
parses a url to a base using pcre
char * BP_ParseURLToHostPCRE(char *long_form_url, BP_BOOL require_dot_in_path_for_match)
{
	char * base = BP_ParseURLToBasePCRE(long_form_url);
	if(!base)
		return NULL;
	char * regexp = NULL;
	if(require_dot_in_path_for_match)
		regexp = GENERIC_MATCH_HOST_FROM_BASE_REQUIRE_DOT;
	else
		regexp = GENERIC_MATCH_HOST_FROM_BASE_NO_DOT_REQUIRED;
	BP_REGEX_MATCH_INFO match_info = {0};
	size_t matched = BP_MatchRegularExpressionPCRE(long_form_url, bpstrlen(long_form_url), regexp, PCRE_CASELESS, 1024, &match_info, true);
	char *ret_string = NULL;
	if(matched == ERR_SUCCESS)
	{
		if(require_dot_in_path_for_match)
		{
			size_t n = 0;
			for(; n < match_info.pcre_num_matched; n++)
			{
				ret_string = bpstrdup(match_info.preg_matches->matched_string);
				break;
			}
		}
		else
		{
			if(match_info.pcre_num_matched >= 2)
			{
				ret_string = bpstrdup(match_info.preg_matches[1].matched_string);
			}
		}
	}
	else
	{
	}
	bpfree(base);
	BP_DestroyRegexpMatchInfo(&match_info);
	return ret_string;
}
char * BP_ParseURLToHostPCRE ( char * long_form_url , BP_BOOL require_dot_in_path_for_match ) { char * base = BP_ParseURLToBasePCRE ( long_form_url ) ; if ( ! base ) return NULL ; char * regexp = NULL ; if ( require_dot_in_path_for_match ) regexp = GENERIC_MATCH_HOST_FROM_BASE_REQUIRE_DOT ; else regexp = GENERIC_MATCH_HOST_FROM_BASE_NO_DOT_REQUIRED ; BP_REGEX_MATCH_INFO match_info = { 0 } ; size_t matched = BP_MatchRegularExpressionPCRE ( long_form_url , bpstrlen ( long_form_url ) , regexp , PCRE_CASELESS , 1024 , & match_info , true ) ; char * ret_string = NULL ; if ( matched == ERR_SUCCESS ) { if ( require_dot_in_path_for_match ) { size_t n = 0 ; for ( ; n < match_info . pcre_num_matched ; n ++ ) { ret_string = bpstrdup ( match_info . preg_matches -> matched_string ) ; break ; } } else { if ( match_info . pcre_num_matched >= 2 ) { ret_string = bpstrdup ( match_info . preg_matches [ 1 ] . matched_string ) ; } } } else { } bpfree ( base ) ; BP_DestroyRegexpMatchInfo ( & match_info ) ; return ret_string ; }
parses a url to a base using pcre
parses a url to a base using pcre
// parse to base first // path matching regexp // create zeroed out inout structure // get matches // set the return string default to null // set matched // check for the matches // display matched string // if no dot is required, it will be the second match // as the first match will be the http/ftp/whatever string // due to extremely loose matching constraints. // printf("\n Got Matched String?: %s", match_info.preg_matches[1].matched_string); // if we don't have at least two matches, we have a bad parse // HOST MATCH FAILED // destroy base // destroy the match info // return null for failure