library/src/blockclass/subclasses/BP_StringUtils.cc
// Adds a unique string to the stack.  Returns false if the string already exists, true if added.
Adds a unique string to the stack.  Returns false if the string already exists, true if added.
Adds a unique string to the stack . Returns false if the string already exists true if added .
bool BP_StringUtils::AddUniqueString(char *str)
{
	if(!str)
	{
		this->AddErr("No string passed to unique stacker.");
		return false;
	}
	size_t i = 0;
	for(; i< this->unique_str_cnt; i++)
	{
		size_t min_check = strnlen(this->unique_strings[i], 4096);
		if(!min_check)
			continue;
		size_t max_check = strnlen(str, 4096);
		if(min_check < max_check)
			continue;
		if(memcmp(this->unique_strings[i], str, bpstrlen(str) ) == 0)
		{
			this->unique_string_index_counts[i]++;
			return false;
		}
	}
	this->unique_str_cnt++;
	this->unique_strings = (char **) tq_realloc(this->tq, this->unique_strings, sizeof(char *) * ( this->unique_str_cnt + 1 ) , BPLN);
	this->unique_string_index_counts = (size_t *) tq_realloc(this->tq, this->unique_string_index_counts, sizeof(size_t) * (this->unique_str_cnt +1 ), BPLN );
	this->unique_string_index_counts[this->unique_str_cnt-1] = 1;
	if(this->duplicate_unique_strings)
		this->unique_strings[this->unique_str_cnt-1] = tq_strdup(this->tq, str, BPLN);
	else
		this->unique_strings[this->unique_str_cnt-1] = str;
	this->unique_strings[this->unique_str_cnt]   = NULL;
	return true;
}
bool BP_StringUtils :: AddUniqueString ( char * str ) { if ( ! str ) { this -> AddErr ( " " ) ; return false ; } size_t i = 0 ; for ( ; i < this -> unique_str_cnt ; i ++ ) { size_t min_check = strnlen ( this -> unique_strings [ i ] , 4096 ) ; if ( ! min_check ) continue ; size_t max_check = strnlen ( str , 4096 ) ; if ( min_check < max_check ) continue ; if ( memcmp ( this -> unique_strings [ i ] , str , bpstrlen ( str ) ) == 0 ) { this -> unique_string_index_counts [ i ] ++ ; return false ; } } this -> unique_str_cnt ++ ; this -> unique_strings = ( char * * ) tq_realloc ( this -> tq , this -> unique_strings , sizeof ( char * ) * ( this -> unique_str_cnt + 1 ) , BPLN ) ; this -> unique_string_index_counts = ( size_t * ) tq_realloc ( this -> tq , this -> unique_string_index_counts , sizeof ( size_t ) * ( this -> unique_str_cnt + 1 ) , BPLN ) ; this -> unique_string_index_counts [ this -> unique_str_cnt - 1 ] = 1 ; if ( this -> duplicate_unique_strings ) this -> unique_strings [ this -> unique_str_cnt - 1 ] = tq_strdup ( this -> tq , str , BPLN ) ; else this -> unique_strings [ this -> unique_str_cnt - 1 ] = str ; this -> unique_strings [ this -> unique_str_cnt ] = NULL ; return true ; }
Adds a unique string to the stack.
Adds a unique string to the stack .
// ensure we have a string being passed in // walk strings and check if string exists // add string to list if its not found // add space for iterative counter // since this is the first iteration, add the update count as first value (1) // duplicate the string where necessary (auto-free'd on delete) // return indicating success (string added)