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_ParseURLToBasePCRE(char *long_form_url, BP_BOOL require_valid_tld)
{
	if(!long_form_url)
		return NULL;
	if(!BP_StringIsReasonablePrintableString(long_form_url, bpstrlen(long_form_url), BP_FALSE, BP_FALSE))
		return NULL;
	char * regexp = NULL;
	if(require_valid_tld)
		regexp = GENERIC_MATCH_BASE_FROM_START_REQUIRE_TLD;
	else
		regexp = GENERIC_MATCH_BASE_FROM_START_TLD_NOT_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)
	{
		size_t n = 0;
		for(; n < match_info.pcre_num_matched; n++)
		{
			ret_string = bpstrdup(match_info.preg_matches->matched_string);
			break;
		}
	}
	BP_DestroyRegexpMatchInfo(&match_info);
	return ret_string;
}
char * BP_ParseURLToBasePCRE ( char * long_form_url , BP_BOOL require_valid_tld ) { if ( ! long_form_url ) return NULL ; if ( ! BP_StringIsReasonablePrintableString ( long_form_url , bpstrlen ( long_form_url ) , BP_FALSE , BP_FALSE ) ) return NULL ; char * regexp = NULL ; if ( require_valid_tld ) regexp = GENERIC_MATCH_BASE_FROM_START_REQUIRE_TLD ; else regexp = GENERIC_MATCH_BASE_FROM_START_TLD_NOT_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 ) { size_t n = 0 ; for ( ; n < match_info . pcre_num_matched ; n ++ ) { ret_string = bpstrdup ( match_info . preg_matches -> matched_string ) ; break ; } } BP_DestroyRegexpMatchInfo ( & match_info ) ; return ret_string ; }
parses a url to a base using pcre
parses a url to a base using pcre
// old path regexp // char * regexp = "[hH][tT][tT][pP][sS]?://(?:[\\w-]+\\.)(?:\\.?[\\w]{2,})+";; // new regexp // run valid tld match // create zeroed out inout structure // get matches (ignore case) // set the return string default to null // set matched //printf("\n BASE MATCHED?!!!"); // check for the matches //printf("\n BASE MATCHED?!!!: %s", match_info.preg_matches->matched_string); // display matched string // destroy the match info // return null for failure