library/src/utility/BP-StringUtilities.cc
// Simply joins two strings and returns a heap buffer for you to use.  This routine
// is not binary safe, and should only be used on strings which you'd feel safe supplying
// to strdup.
Simply joins two strings and returns a heap buffer for you to use.  This routine
is not binary safe, and should only be used on strings which you'd feel safe supplying
to strdup.
Simply joins two strings and returns a heap buffer for you to use . This routine is not binary safe and should only be used on strings which you ' d feel safe supplying to strdup .
char * BP_JoinStrings(char *string_front, char *string_tail, P_BP_LINKL tq_in)
{
	if(!string_front)
	{
		string_front = "";
	}
	if(!string_tail)
	{
		string_tail = "";
	}
	if(!string_front || !string_tail)
		return NULL;
	P_BP_LINKL tq = BP_CreateLinkL(".", BP_FALSE);
	if(!tq)
		return NULL;
	size_t front_len = bpstrlen(string_front);
	size_t tail_len   = bpstrlen(string_tail);
	if(!front_len && tail_len)
	{
		BP_DestroyLinkL(tq, BP_TRUE);
		if(tq_in)
			return tq_strdup(tq_in, string_tail, BPLN);
		else
			return bpstrdup(string_tail);
	}
	if(front_len && !tail_len)
	{
		BP_DestroyLinkL(tq, BP_TRUE);
		if(tq_in)
			return tq_strdup(tq_in, string_front, BPLN);
		else
			return bpstrdup(string_tail);
	}
	if(!tq_strdup(tq, string_front, BPLN))
	{
		BP_DestroyLinkL(tq, BP_TRUE);
		return NULL;
	}
	if(!tq_strdup(tq, string_tail, BPLN))
	{
		BP_DestroyLinkL(tq, BP_TRUE);
		return NULL;
	}
	if(BP_LinkLFlattenJoinStringElements(tq) != ERR_SUCCESS)
	{
		BP_DestroyLinkL(tq, BP_TRUE);
		return NULL;
	}
	char *final_buffer = NULL;
	if(tq->flat_buff)
	{
		final_buffer = bpstrdup((char *) tq->flat_buff);
	}
	BP_DestroyLinkL(tq, BP_TRUE);
	if(tq_in)
	{
		tq_link(tq_in, final_buffer, front_len + tail_len + 1, BPLN);
	}
	return final_buffer;
}
char * BP_JoinStrings ( char * string_front , char * string_tail , P_BP_LINKL tq_in ) { if ( ! string_front ) { string_front = " " ; } if ( ! string_tail ) { string_tail = " " ; } if ( ! string_front || ! string_tail ) return NULL ; P_BP_LINKL tq = BP_CreateLinkL ( " " , BP_FALSE ) ; if ( ! tq ) return NULL ; size_t front_len = bpstrlen ( string_front ) ; size_t tail_len = bpstrlen ( string_tail ) ; if ( ! front_len && tail_len ) { BP_DestroyLinkL ( tq , BP_TRUE ) ; if ( tq_in ) return tq_strdup ( tq_in , string_tail , BPLN ) ; else return bpstrdup ( string_tail ) ; } if ( front_len && ! tail_len ) { BP_DestroyLinkL ( tq , BP_TRUE ) ; if ( tq_in ) return tq_strdup ( tq_in , string_front , BPLN ) ; else return bpstrdup ( string_tail ) ; } if ( ! tq_strdup ( tq , string_front , BPLN ) ) { BP_DestroyLinkL ( tq , BP_TRUE ) ; return NULL ; } if ( ! tq_strdup ( tq , string_tail , BPLN ) ) { BP_DestroyLinkL ( tq , BP_TRUE ) ; return NULL ; } if ( BP_LinkLFlattenJoinStringElements ( tq ) != ERR_SUCCESS ) { BP_DestroyLinkL ( tq , BP_TRUE ) ; return NULL ; } char * final_buffer = NULL ; if ( tq -> flat_buff ) { final_buffer = bpstrdup ( ( char * ) tq -> flat_buff ) ; } BP_DestroyLinkL ( tq , BP_TRUE ) ; if ( tq_in ) { tq_link ( tq_in , final_buffer , front_len + tail_len + 1 , BPLN ) ; } return final_buffer ; }
Simply joins two strings and returns a heap buffer for you to use.
Simply joins two strings and returns a heap buffer for you to use .
// create string front or tail if they don't already exist // create tail // ensure we have parameters // create linkl or exit if we cant // run length calculations first // Just return a a tail if there's no front part // dupe the front // dupe the tail // flatten the tq // this is the buffer which gets returned // copy the final buffer // destroy the final tailqueue // check if we have an output tailueue // link the final buffer if we have a tailqueue to link it in // return the final buffer