library/src/utility/BP-StringUtilities.cc
// parses a url to a path using pcre
parses a url to a path using pcre
parses a url to a path using pcre
char * BP_ParseURLToPathPCRE(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_PATH_FROM_START_REQUIRE_TLD;
	else
		regexp = GENERIC_MATCH_PATH_FROM_START_TLD_NOT_REQUIRED;
	regexp = "[a-zA-Z]{1,}\\:\\/\\/[\\!\\:\\@\\.a-zA-Z0-9\\-]{1,}(?:[\\.a-zA-Z0-9\\-]{1,})(?:[\\:\\/0-9]{0,})\\/(?:([\\.\\_\\/\\~0-9a-zA-Z]){0,})\\/";
	BP_REGEX_MATCH_INFO match_info;
	BP_ZERO_STACK(match_info);
	int regexp_flags    = 0;
	regexp_flags           |= PCRE_MULTILINE;
	regexp_flags           |= PCRE_DOTALL;
	size_t matched = BP_MatchRegularExpressionPCRE(long_form_url, bpstrlen(long_form_url), regexp, regexp_flags, 3, (P_BP_REGEX_MATCH_INFO) &match_info, true);
	char *ret_string = NULL;
	if(matched == ERR_SUCCESS)
	{
		size_t n = 0;
		for(; n < match_info.pcre_num_matched; n++)
		{
			char *ret = (char *) bpcalloc(match_info.preg_matches[n].match_len+16, 1);
			memcpy(ret, match_info.preg_matches[n].matched_string, match_info.preg_matches[n].match_len);
			ret_string = ret;
			break;
		}
	}
	else
	{
	}
	BP_DestroyRegexpMatchInfo(&match_info);
	if(!ret_string)
	{
		ret_string = BP_ParseURLToBasePCRE(long_form_url, require_valid_tld);
	}
	return ret_string;
}
char * BP_ParseURLToPathPCRE ( 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_PATH_FROM_START_REQUIRE_TLD ; else regexp = GENERIC_MATCH_PATH_FROM_START_TLD_NOT_REQUIRED ; regexp = " \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ " ; BP_REGEX_MATCH_INFO match_info ; BP_ZERO_STACK ( match_info ) ; int regexp_flags = 0 ; regexp_flags |= PCRE_MULTILINE ; regexp_flags |= PCRE_DOTALL ; size_t matched = BP_MatchRegularExpressionPCRE ( long_form_url , bpstrlen ( long_form_url ) , regexp , regexp_flags , 3 , ( P_BP_REGEX_MATCH_INFO ) & match_info , true ) ; char * ret_string = NULL ; if ( matched == ERR_SUCCESS ) { size_t n = 0 ; for ( ; n < match_info . pcre_num_matched ; n ++ ) { char * ret = ( char * ) bpcalloc ( match_info . preg_matches [ n ] . match_len + 16 , 1 ) ; memcpy ( ret , match_info . preg_matches [ n ] . matched_string , match_info . preg_matches [ n ] . match_len ) ; ret_string = ret ; break ; } } else { } BP_DestroyRegexpMatchInfo ( & match_info ) ; if ( ! ret_string ) { ret_string = BP_ParseURLToBasePCRE ( long_form_url , require_valid_tld ) ; } return ret_string ; }
parses a url to a path using pcre
parses a url to a path using pcre
// ensure we have a parameter // path matching regexp // char * regexp = "[hH][tT][tT][pP][sS]?://(?:[\\w-]+\\.)(?:\\.?[\\w-]{2,})+(?:[\\/~\\w\\-0-9]+)[\\/]"; // new regexp matching iana standards domains // char * regexp = "[a-zA-Z]{3,}\\:\\/\\/(?:[\\w-]+\\.)+(?:construction|photography|enterprises|contractors|technology|equipment|directory|ventures|plumbing|lighting|holdings|graphics|diamonds|clothing|singles|kitchen|gallery|voyage|travel|tattoo|museum|estate|camera|today|tips|sexy|post|name|mobi|menu|land|jobs|info|guru|coop|bike|asia|arpa|aero|xxx|uno|tel|pro|org|net|mil|int|gov|edu|com|cat|biz|zw|zm|za|yt|ye|ws|wf|vu|vn|vi|vg|ve|vc|va|uz|uy|us|uk|ug|ua|tz|tw|tv|tt|tr|tp|to|tn|tm|tl|tk|tj|th|tg|tf|td|tc|sz|sy|sx|sv|su|st|sr|so|sn|sm|sl|sk|sj|si|sh|sg|se|sd|sc|sb|sa|rw|ru|rs|ro|re|qa|py|pw|pt|ps|pr|pn|pm|pl|pk|ph|pg|pf|pe|pa|om|nz|nu|nr|np|no|nl|ni|ng|nf|ne|nc|na|mz|my|mx|mw|mv|mu|mt|ms|mr|mq|mp|mo|mn|mm|ml|mk|mh|mg|me|md|mc|ma|ly|lv|lu|lt|ls|lr|lk|li|lc|lb|la|kz|ky|kw|kr|kp|kn|km|ki|kh|kg|ke|jp|jo|jm|je|it|is|ir|iq|io|in|im|il|ie|id|hu|ht|hr|hn|hm|hk|gy|gw|gu|gt|gs|gr|gq|gp|gn|gm|gl|gi|gh|gg|gf|ge|gd|gb|ga|fr|fo|fm|fk|fj|fi|eu|et|es|er|eg|ee|ec|dz|do|dm|dk|dj|de|cz|cy|cx|cw|cv|cu|cr|co|cn|cm|cl|ck|ci|ch|cg|cf|cd|cc|ca|bz|by|bw|bv|bt|bs|br|bo|bn|bm|bj|bi|bh|bg|bf|be|bd|bb|ba|az|ax|aw|au|at|as|ar|aq|ao|an|am|al|ai|ag|af|ae|ad|ac)+ [\\/]"; // char * regexp =  "[a-zA-Z]{3,}\\:\\/\\/(?:[a-zA-Z0-9-@\\:]+\\.|[a-zA-Z0-9-@\\:]+\\.{1,})+(?:construction|photography|enterprises|contractors|technology|equipment|directory|ventures|plumbing|lighting|holdings|graphics|diamonds|clothing|singles|kitchen|gallery|voyage|travel|tattoo|museum|estate|camera|today|tips|sexy|post|name|mobi|menu|land|jobs|info|guru|coop|bike|asia|arpa|aero|xxx|uno|tel|pro|org|net|mil|int|gov|edu|com|cat|biz|zw|zm|za|yt|ye|ws|wf|vu|vn|vi|vg|ve|vc|va|uz|uy|us|uk|ug|ua|tz|tw|tv|tt|tr|tp|to|tn|tm|tl|tk|tj|th|tg|tf|td|tc|sz|sy|sx|sv|su|st|sr|so|sn|sm|sl|sk|sj|si|sh|sg|se|sd|sc|sb|sa|rw|ru|rs|ro|re|qa|py|pw|pt|ps|pr|pn|pm|pl|pk|ph|pg|pf|pe|pa|om|nz|nu|nr|np|no|nl|ni|ng|nf|ne|nc|na|mz|my|mx|mw|mv|mu|mt|ms|mr|mq|mp|mo|mn|mm|ml|mk|mh|mg|me|md|mc|ma|ly|lv|lu|lt|ls|lr|lk|li|lc|lb|la|kz|ky|kw|kr|kp|kn|km|ki|kh|kg|ke|jp|jo|jm|je|it|is|ir|iq|io|in|im|il|ie|id|hu|ht|hr|hn|hm|hk|gy|gw|gu|gt|gs|gr|gq|gp|gn|gm|gl|gi|gh|gg|gf|ge|gd|gb|ga|fr|fo|fm|fk|fj|fi|eu|et|es|er|eg|ee|ec|dz|do|dm|dk|dj|de|cz|cy|cx|cw|cv|cu|cr|co|cn|cm|cl|ck|ci|ch|cg|cf|cd|cc|ca|bz|by|bw|bv|bt|bs|br|bo|bn|bm|bj|bi|bh|bg|bf|be|bd|bb|ba|az|ax|aw|au|at|as|ar|aq|ao|an|am|al|ai|ag|af|ae|ad|ac)(?:[:0-9]?)+(?:\\/[\\/~\\w\\-0-9]+\\/|\\/)"; // "[a-zA-Z0-9\-]{1,}\\:\\/\\/[\\!\\:\\@\\.a-zA-Z0-9\\-]{1,}(?:[\\.a-zA-Z0-9\\-]{1,})(?:\\.construction|\\.photography|\\.enterprises|\\.contractors|\\.technology|\\.equipment|\\.directory|\\.ventures|\\.plumbing|\\.lighting|\\.holdings|\\.graphics|\\.diamonds|\\.clothing|\\.singles|\\.kitchen|\\.gallery|\\.voyage|\\.travel|\\.tattoo|\\.museum|\\.estate|\\.camera|\\.today|\\.tips|\\.sexy|\\.post|\\.name|\\.mobi|\\.menu|\\.land|\\.jobs|\\.info|\\.guru|\\.coop|\\.bike|\\.asia|\\.arpa|\\.aero|\\.xxx|\\.uno|\\.tel|\\.pro|\\.org|\\.net|\\.mil|\\.int|\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\.gd|\\.gb|\\.ga|\\.fr|\\.fo|\\.fm|\\.fk|\\.fj|\\.fi|\\.eu|\\.et|\\.es|\\.er|\\.eg|\\.ee|\\.ec|\\.dz|\\.do|\\.dm|\\.dk|\\.dj|\\.de|\\.cz|\\.cy|\\.cx|\\.cw|\\.cv|\\.cu|\\.cr|\\.co|\\.cn|\\.cm|\\.cl|\\.ck|\\.ci|\\.ch|\\.cg|\\.cf|\\.cd|\\.cc|\\.ca|\\.bz|\\.by|\\.bw|\\.bv|\\.bt|\\.bs|\\.br|\\.bo|\\.bn|\\.bm|\\.bj|\\.bi|\\.bh|\\.bg|\\.bf|\\.be|\\.bd|\\.bb|\\.ba|\\.az|\\.ax|\\.aw|\\.au|\\.at|\\.as|\\.ar|\\.aq|\\.ao|\\.an|\\.am|\\.al|\\.ai|\\.ag|\\.af|\\.ae|\\.ad|\\.ac){1,}(?:[\\:\\/0-9]{0,})\\/(?:[0-9a-zA-Z\\-\\~]{1,}[\\/])"; //regexp = "(?:([a-zA-Z0-9\-]{1,10}))(?:([:][\\/][\\/]{1,1}))"; // create zeroed out inout structure // get matches // set the return string default to null // set matched // check for the matches // allocate space for data // copy data in // printf("\n Path not matched: %s - %s", regexp, long_form_url); // destroy the match info // if we can't parse it to a path, try to parse it to a base // return null for failure