library/src/utility/BP-StringUtilities.cc
// parses a string to a url
parses a string to a url
parses a string to a url
char * BP_ParseStringToURLPCRE(char *long_form_url, BP_BOOL require_valid_tld_match)
{
	if(!long_form_url)
		return NULL;
	BP_REGEX_MATCH_INFO match_info = {0};
	size_t matched = 0;
	if(require_valid_tld_match)
		matched = BP_MatchRegularExpressionPCRE(long_form_url, bpstrlen(long_form_url), GENERIC_MATCH_URL_FROM_START_PCRE,           PCRE_CASELESS, 1024, &match_info, true);
	else
		matched = BP_MatchRegularExpressionPCRE(long_form_url, bpstrlen(long_form_url), GENERIC_MATCH_URL_FROM_START_NON_STRICT_TLD, 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_ParseStringToURLPCRE ( char * long_form_url , BP_BOOL require_valid_tld_match ) { if ( ! long_form_url ) return NULL ; BP_REGEX_MATCH_INFO match_info = { 0 } ; size_t matched = 0 ; if ( require_valid_tld_match ) matched = BP_MatchRegularExpressionPCRE ( long_form_url , bpstrlen ( long_form_url ) , GENERIC_MATCH_URL_FROM_START_PCRE , PCRE_CASELESS , 1024 , & match_info , true ) ; else matched = BP_MatchRegularExpressionPCRE ( long_form_url , bpstrlen ( long_form_url ) , GENERIC_MATCH_URL_FROM_START_NON_STRICT_TLD , 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 string to a url
parses a string to a url
// create zeroed out inout structure // get matches // check if the user specified whether or not to do forced tld matching // set the return string default to null // set matched // check for the matches // display matched string // destroy the match info // return null for failure