library/src/javascript/JSON/BP-JSON.cc
// Attempts to retrieve a string value represenation of a primitive (exactly as BP_JSONGetStringValueFromJSMNToken(), with different type check)
Attempts to retrieve a string value represenation of a primitive (exactly as BP_JSONGetStringValueFromJSMNToken(), with different type check)
Attempts to retrieve a string value represenation of a primitive ( exactly as BP_JSONGetStringValueFromJSMNToken () with different type check )
char * BP_JSONGetPrimitiveValueAsStringValueFromJSMNToken(P_BP_JSON_PARSE_STATE parse_state, jsmntok_t *token)
{
	if(!parse_state)
		return NULL;
	if(!token)
		return NULL;
	if(token->type != JSMN_PRIMITIVE)
		return NULL;
	if(!parse_state->buffer)
		return NULL;
	if(!parse_state->buffer_size)
		return NULL;
	if(!BP_StringIsReasonablePrintableString(parse_state->buffer, parse_state->buffer_size, BP_TRUE, BP_TRUE))
		return NULL;
	if(token->start == -1)
		return NULL;
	if(token->end == -1)
		return NULL;
	if(token->start >= parse_state->buffer_size)
		return NULL;
	if(token->end >= parse_state->buffer_size)
		return NULL;
	size_t token_buff_len = 0;
	int size_calc = token->end - token->start;
	if(size_calc <= 0)
		return NULL;
	token_buff_len = (size_t) size_calc;
	char *token_value_as_string = bpstrndup((char *) &parse_state->buffer[token->start], token_buff_len);
	if(!token_value_as_string)
		return NULL;
	return token_value_as_string;
}
char * BP_JSONGetPrimitiveValueAsStringValueFromJSMNToken ( P_BP_JSON_PARSE_STATE parse_state , jsmntok_t * token ) { if ( ! parse_state ) return NULL ; if ( ! token ) return NULL ; if ( token -> type != JSMN_PRIMITIVE ) return NULL ; if ( ! parse_state -> buffer ) return NULL ; if ( ! parse_state -> buffer_size ) return NULL ; if ( ! BP_StringIsReasonablePrintableString ( parse_state -> buffer , parse_state -> buffer_size , BP_TRUE , BP_TRUE ) ) return NULL ; if ( token -> start == -1 ) return NULL ; if ( token -> end == -1 ) return NULL ; if ( token -> start >= parse_state -> buffer_size ) return NULL ; if ( token -> end >= parse_state -> buffer_size ) return NULL ; size_t token_buff_len = 0 ; int size_calc = token -> end - token -> start ; if ( size_calc <= 0 ) return NULL ; token_buff_len = ( size_t ) size_calc ; char * token_value_as_string = bpstrndup ( ( char * ) & parse_state -> buffer [ token -> start ] , token_buff_len ) ; if ( ! token_value_as_string ) return NULL ; return token_value_as_string ; }
Attempts to retrieve a string value represenation of a primitive (exactly as BP_JSONGetStringValueFromJSMNToken(), with different type check)
Attempts to retrieve a string value represenation of a primitive ( exactly as BP_JSONGetStringValueFromJSMNToken () with different type check )
// ensure we have a parse state // ensure we have a token // type must be JSMN_PRIMITIVE // ensure we have a buffer and a buffer size // ensure the buffer being passed in is reasonable/printable (since it's being used for extraction) // neither start nor end can be -1 // printf("\n GETS THIS FAR IN CHECKS?"); // check to ensure that the start isn't past the end of our buffer // ensure that the end isn't past the end of our buffer // buffer length // calculate the size of the buffer // ensure the size calculation is reasonable // convert to size_t after negative check // token size isn't set in string types // if(token->size) // go ahead and copy out values now using strndup() // exit if duplication failed for whatever reason // return indicating success