library/src/blockclass/subclasses/BP_StringUtils.cc
// Creates a character * pointer array containing a set of exploded() values.
Creates a character * pointer array containing a set of exploded() values.
Creates a character * pointer array containing a set of exploded () values .
bool BP_StringUtils::Explode(char *reg_delim)
{
	if(!reg_delim)
		return false;
	if(!this->string)
		return false;
	char ** replacements    = NULL;
	size_t num_replacements = 0;
	BP_REGEX_MATCH_INFO   reg_match = {0};
	reg_match.matches      = NULL;
	reg_match.num_matched = 0;
	size_t is_match_you_want = 0;
	if(memcmp(reg_delim, " | ", 3) == 0)
	{
		is_match_you_want++;
	}
	size_t num_toks = 0;
	char *tok_str = this->string;
	char *element = NULL;
	for(;
		BP_MatchRegularExpression(tok_str, bpstrlen(tok_str), reg_delim, 0, 1, &reg_match) == ERR_SUCCESS;
		num_toks++
		)
	{
		if(reg_match.num_matched != 0)
		{
			element = tq_strndup(this->tq, tok_str, reg_match.matches->rm_so+1, BPLN);
			element[bpstrlen(element)-1] = 0x00;
			tok_str = (char *)&tok_str[reg_match.matches->rm_eo];
			num_replacements++;
			replacements = (char **) tq_realloc(this->tq,  replacements, sizeof(char*) * (num_replacements + 1) , BPLN);
			replacements[num_replacements-1] = element;
			replacements[num_replacements]   = NULL;
		}
		else
		{
			BP_DestroyRegexpMatchInfo(&reg_match);
			break;
		}
		BP_DestroyRegexpMatchInfo(&reg_match);
		reg_match.matches      = NULL;
		reg_match.num_matched = 0;
	}
	if(num_replacements)
	{
		num_replacements++;
		replacements = (char **) tq_realloc(this->tq, replacements, sizeof(char*) * (num_replacements+1) , BPLN);
		element = tq_strdup(this->tq, tok_str, BPLN);
		replacements[num_replacements - 1] = element;
		replacements[num_replacements] = NULL;
	}
	this->exploded       = replacements;
	this->exploded_count = num_replacements;
	return true;
}
bool BP_StringUtils :: Explode ( char * reg_delim ) { if ( ! reg_delim ) return false ; if ( ! this -> string ) return false ; char * * replacements = NULL ; size_t num_replacements = 0 ; BP_REGEX_MATCH_INFO reg_match = { 0 } ; reg_match . matches = NULL ; reg_match . num_matched = 0 ; size_t is_match_you_want = 0 ; if ( memcmp ( reg_delim , " " , 3 ) == 0 ) { is_match_you_want ++ ; } size_t num_toks = 0 ; char * tok_str = this -> string ; char * element = NULL ; for ( ; BP_MatchRegularExpression ( tok_str , bpstrlen ( tok_str ) , reg_delim , 0 , 1 , & reg_match ) == ERR_SUCCESS ; num_toks ++ ) { if ( reg_match . num_matched != 0 ) { element = tq_strndup ( this -> tq , tok_str , reg_match . matches -> rm_so + 1 , BPLN ) ; element [ bpstrlen ( element ) - 1 ] = 0x00 ; tok_str = ( char * ) & tok_str [ reg_match . matches -> rm_eo ] ; num_replacements ++ ; replacements = ( char * * ) tq_realloc ( this -> tq , replacements , sizeof ( char * ) * ( num_replacements + 1 ) , BPLN ) ; replacements [ num_replacements - 1 ] = element ; replacements [ num_replacements ] = NULL ; } else { BP_DestroyRegexpMatchInfo ( & reg_match ) ; break ; } BP_DestroyRegexpMatchInfo ( & reg_match ) ; reg_match . matches = NULL ; reg_match . num_matched = 0 ; } if ( num_replacements ) { num_replacements ++ ; replacements = ( char * * ) tq_realloc ( this -> tq , replacements , sizeof ( char * ) * ( num_replacements + 1 ) , BPLN ) ; element = tq_strdup ( this -> tq , tok_str , BPLN ) ; replacements [ num_replacements - 1 ] = element ; replacements [ num_replacements ] = NULL ; } this -> exploded = replacements ; this -> exploded_count = num_replacements ; return true ; }
Creates a character * pointer array containing a set of exploded() values.
Creates a character * pointer array containing a set of exploded () values .
// ensure we have a delimiter to explode buffer with // ensure we have a string set in the class // first get number of replacements // create match info loop // for detecting bugs in string // walk regular expressions and create duplication strings // %%% Done quote detection %%%%%%%%%%%%%%%%%%%%%%% // duplicate element // terminate element if necessary // move token string forward // bprealloc space for replacements // set replacements in array // break the loop as we've hit the last element // add tail end of string as element // increment replacements counter // bprealloc space for replacements // create final element // set replacements in array // first get number of replacements // return indicating success