library/src/utility/BP-StringUtilities.cc
// joins all elements in string_array by calling BP_JoinStrings on each element consecutively.
joins all elements in string_array by calling BP_JoinStrings on each element consecutively.
joins all elements in string_array by calling BP_JoinStrings on each element consecutively .
char * BP_JoinStringArray(char ** string_array, size_t entry_count, P_BP_LINKL tq_in)
{
	if(!string_array || !entry_count)
		return NULL;
	if(entry_count < 2)
		return NULL;
	if(entry_count == 2)
		return BP_JoinStrings(string_array[0], string_array[1], tq_in);
	char * final_buffer = NULL;
	char * last_buffer = NULL;
	BP_BOOL is_first_iter = BP_TRUE;
	size_t n = 0;
	for(; n < entry_count; n++)
	{
		if(is_first_iter == BP_TRUE)
		{
			final_buffer = BP_JoinStrings(string_array[0], string_array[1], tq_in);
			if(!final_buffer)
				return NULL;
			last_buffer = final_buffer;
			is_first_iter = BP_FALSE;
			n++;
			continue;
		}
		final_buffer = BP_JoinStrings(last_buffer, string_array[n], tq_in);
		if(tq_in)
		{
			tq_free(tq_in, last_buffer);
			last_buffer = final_buffer;
		}
		else
		{
			bpfree(last_buffer);
			last_buffer = final_buffer;
		}
	}
	return final_buffer;
}
char * BP_JoinStringArray ( char * * string_array , size_t entry_count , P_BP_LINKL tq_in ) { if ( ! string_array || ! entry_count ) return NULL ; if ( entry_count < 2 ) return NULL ; if ( entry_count == 2 ) return BP_JoinStrings ( string_array [ 0 ] , string_array [ 1 ] , tq_in ) ; char * final_buffer = NULL ; char * last_buffer = NULL ; BP_BOOL is_first_iter = BP_TRUE ; size_t n = 0 ; for ( ; n < entry_count ; n ++ ) { if ( is_first_iter == BP_TRUE ) { final_buffer = BP_JoinStrings ( string_array [ 0 ] , string_array [ 1 ] , tq_in ) ; if ( ! final_buffer ) return NULL ; last_buffer = final_buffer ; is_first_iter = BP_FALSE ; n ++ ; continue ; } final_buffer = BP_JoinStrings ( last_buffer , string_array [ n ] , tq_in ) ; if ( tq_in ) { tq_free ( tq_in , last_buffer ) ; last_buffer = final_buffer ; } else { bpfree ( last_buffer ) ; last_buffer = final_buffer ; } } return final_buffer ; }
joins all elements in string_array by calling BP_JoinStrings on each element consecutively.
joins all elements in string_array by calling BP_JoinStrings on each element consecutively .
// ensure we have a string array and an entry count // minimum elements is 2 (front and tail) // return joined string // final buffer for returning to the caller // set initial buffer // notes if we're in the first buffer // walk each entry and join things up // the first iteration requires a few different steps // attempt to join the buffer // ensure we could create the buffer // store the last buffer as the final buffer, so it can be free'd on loop // set flag indicating we're no longer on the first iteration, and continue // the loop. // try to create the final buffer // free last_buffer in tailqueue if set, if not, normal free // return the final buffer