library/src/javascript/JSON/BP-JSON.cc
// Fills the path strings within the provided token element.
Fills the path strings within the provided token element.
Fills the path strings within the provided token element .
BP_ERROR_T BP_JSONGeneratePathBufferRecursivelyFromToken(P_BP_JSON_PARSE_STATE parse_state, P_BP_JSON_PARSE_TOKEN_ELEMENT token_element)
{
	if(!parse_state)
		return ERR_FAILURE;
	if(!token_element)
		return ERR_FAILURE;
	P_BP_LINKL path_builder_tq = BP_CreateLinkL(".", BP_TRUE);
	if(token_element->parent_token_element)
	{
		if(!BP_JSONGeneratePathBufferRecursivelyFromToken_r(parse_state, (P_BP_JSON_PARSE_TOKEN_ELEMENT) token_element->parent_token_element, path_builder_tq))
		{
			BP_DestroyLinkL(path_builder_tq, BP_TRUE);
			return ERR_FAILURE;
		}
	}
	if(token_element->current_token_label_is_anonymous)
	{
		tq_strdup(path_builder_tq, "/", BPLN);
		tq_strdup(path_builder_tq, token_element->current_string_val, BPLN);
	}
	else if(token_element->current_string_val)
	{
		tq_strdup(path_builder_tq, "/", BPLN);
		tq_strdup(path_builder_tq, token_element->current_string_val, BPLN);
	}
	else if(token_element->current_primitive_val)
	{
		tq_strdup(path_builder_tq, "/", BPLN);
		tq_strdup(path_builder_tq, token_element->current_primitive_val, BPLN);
	}
	BP_LinkLFlattenJoinStringElements(path_builder_tq);
	if(token_element->path_query_to_current)
		tq_free(parse_state->tq, token_element->path_query_to_current);
	token_element->path_query_to_current = (char *) tq_strdup(parse_state->tq, (char *) path_builder_tq->flat_buff, BPLN);
	BP_DestroyLinkL(path_builder_tq, BP_TRUE);
	if(!token_element->parent_token_element)
		return ERR_SUCCESS;
	path_builder_tq = BP_CreateLinkL(".", BP_TRUE);
	P_BP_JSON_PARSE_TOKEN_ELEMENT parent_element = (P_BP_JSON_PARSE_TOKEN_ELEMENT) token_element->parent_token_element;
	if(parent_element->parent_token_element)
	{
		if(!BP_JSONGeneratePathBufferRecursivelyFromToken_r(parse_state, (P_BP_JSON_PARSE_TOKEN_ELEMENT) parent_element->parent_token_element, path_builder_tq))
		{
			BP_DestroyLinkL(path_builder_tq, BP_TRUE);
			return ERR_FAILURE;
		}
	}
	if(parent_element->current_token_label_is_anonymous)
	{
		tq_strdup(path_builder_tq, "/", BPLN);
		tq_strdup(path_builder_tq, parent_element->current_string_val, BPLN);
	}
	else if(parent_element->current_string_val)
	{
		tq_strdup(path_builder_tq, "/", BPLN);
		tq_strdup(path_builder_tq, parent_element->current_string_val, BPLN);
	}
	else if(parent_element->current_primitive_val)
	{
		tq_strdup(path_builder_tq, "/", BPLN);
		tq_strdup(path_builder_tq, parent_element->current_primitive_val, BPLN);
	}
	BP_LinkLFlattenJoinStringElements(path_builder_tq);
	if(token_element->path_query_to_parent)
		tq_free(parse_state->tq, token_element->path_query_to_parent);
	token_element->path_query_to_parent = (char *) tq_strdup(parse_state->tq, (char *) path_builder_tq->flat_buff, BPLN);
	BP_DestroyLinkL(path_builder_tq, BP_TRUE);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_JSONGeneratePathBufferRecursivelyFromToken ( P_BP_JSON_PARSE_STATE parse_state , P_BP_JSON_PARSE_TOKEN_ELEMENT token_element ) { if ( ! parse_state ) return ERR_FAILURE ; if ( ! token_element ) return ERR_FAILURE ; P_BP_LINKL path_builder_tq = BP_CreateLinkL ( " " , BP_TRUE ) ; if ( token_element -> parent_token_element ) { if ( ! BP_JSONGeneratePathBufferRecursivelyFromToken_r ( parse_state , ( P_BP_JSON_PARSE_TOKEN_ELEMENT ) token_element -> parent_token_element , path_builder_tq ) ) { BP_DestroyLinkL ( path_builder_tq , BP_TRUE ) ; return ERR_FAILURE ; } } if ( token_element -> current_token_label_is_anonymous ) { tq_strdup ( path_builder_tq , " " , BPLN ) ; tq_strdup ( path_builder_tq , token_element -> current_string_val , BPLN ) ; } else if ( token_element -> current_string_val ) { tq_strdup ( path_builder_tq , " " , BPLN ) ; tq_strdup ( path_builder_tq , token_element -> current_string_val , BPLN ) ; } else if ( token_element -> current_primitive_val ) { tq_strdup ( path_builder_tq , " " , BPLN ) ; tq_strdup ( path_builder_tq , token_element -> current_primitive_val , BPLN ) ; } BP_LinkLFlattenJoinStringElements ( path_builder_tq ) ; if ( token_element -> path_query_to_current ) tq_free ( parse_state -> tq , token_element -> path_query_to_current ) ; token_element -> path_query_to_current = ( char * ) tq_strdup ( parse_state -> tq , ( char * ) path_builder_tq -> flat_buff , BPLN ) ; BP_DestroyLinkL ( path_builder_tq , BP_TRUE ) ; if ( ! token_element -> parent_token_element ) return ERR_SUCCESS ; path_builder_tq = BP_CreateLinkL ( " " , BP_TRUE ) ; P_BP_JSON_PARSE_TOKEN_ELEMENT parent_element = ( P_BP_JSON_PARSE_TOKEN_ELEMENT ) token_element -> parent_token_element ; if ( parent_element -> parent_token_element ) { if ( ! BP_JSONGeneratePathBufferRecursivelyFromToken_r ( parse_state , ( P_BP_JSON_PARSE_TOKEN_ELEMENT ) parent_element -> parent_token_element , path_builder_tq ) ) { BP_DestroyLinkL ( path_builder_tq , BP_TRUE ) ; return ERR_FAILURE ; } } if ( parent_element -> current_token_label_is_anonymous ) { tq_strdup ( path_builder_tq , " " , BPLN ) ; tq_strdup ( path_builder_tq , parent_element -> current_string_val , BPLN ) ; } else if ( parent_element -> current_string_val ) { tq_strdup ( path_builder_tq , " " , BPLN ) ; tq_strdup ( path_builder_tq , parent_element -> current_string_val , BPLN ) ; } else if ( parent_element -> current_primitive_val ) { tq_strdup ( path_builder_tq , " " , BPLN ) ; tq_strdup ( path_builder_tq , parent_element -> current_primitive_val , BPLN ) ; } BP_LinkLFlattenJoinStringElements ( path_builder_tq ) ; if ( token_element -> path_query_to_parent ) tq_free ( parse_state -> tq , token_element -> path_query_to_parent ) ; token_element -> path_query_to_parent = ( char * ) tq_strdup ( parse_state -> tq , ( char * ) path_builder_tq -> flat_buff , BPLN ) ; BP_DestroyLinkL ( path_builder_tq , BP_TRUE ) ; return ERR_SUCCESS ; }
Fills the path strings within the provided token element.
Fills the path strings within the provided token element .
// basic null checks // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Step 1: Generate Full Path to Element %%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create new talqueue allocator for generating linkl // if we have a parent token, immediately recurse // recurse and attempt to generate token // --- Add Path Values ----------------------- // if the current item is anonymous, use the anonymous parent string here // flatten the linkl to create single string // destroy current info if set // duplicate the path to the current item as our path to current element // destroy the linkl before exiting // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Step 2: Generate Full Path to Parent %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // only continue if we have a parent token element to work with (if not we're at top position) // create new linkl for parsing parent // cast parent element from token (void *) // if we have a parent token, immediately recurse // recurse and attempt to generate token // --- Add Path Values ----------------------- // if the current item is anonymous, use the anonymous parent string here // --- Flatten and Set Values --------------------------------- // flatten the linkl to create single string // destroy parent info if set // duplicate the path to the parent item as our path to current element // destroy the linkl before exiting // return indicating success