library/src/javascript/JSON/BP-JSON.cc
// Attempts to create JSON from a file.  Reads entire file and attempts to parse into JSON.
Attempts to create JSON from a file.  Reads entire file and attempts to parse into JSON.
Attempts to create JSON from a file . Reads entire file and attempts to parse into JSON .
P_BP_JSON BP_JSONCreateFromFile(char *filename, size_t max_depth_for_token_allocation, size_t max_tokens_total)
{
	if(!filename)
		return NULL;
	BP_FILE_LOAD_EXTRA_INFO extra_info;
	BP_ZERO_STACK(extra_info);
	char *buffer = BP_FileGetContents(filename, &extra_info);
	if(!buffer)
	{
		return NULL;
	}
	P_BP_JSON json = (P_BP_JSON) BP_JSONCreate();
	if(!json)
	{
		bpfree(buffer);
		return NULL;
	}
	if(!BP_JSONParseFromBuffer(json, buffer, extra_info.file_size, max_depth_for_token_allocation, max_tokens_total))
	{
		bpfree(buffer);
		BP_JSONDestroy(json);
		return NULL;
	}
	bpfree(buffer);
	return json;
}
P_BP_JSON BP_JSONCreateFromFile ( char * filename , size_t max_depth_for_token_allocation , size_t max_tokens_total ) { if ( ! filename ) return NULL ; BP_FILE_LOAD_EXTRA_INFO extra_info ; BP_ZERO_STACK ( extra_info ) ; char * buffer = BP_FileGetContents ( filename , & extra_info ) ; if ( ! buffer ) { return NULL ; } P_BP_JSON json = ( P_BP_JSON ) BP_JSONCreate ( ) ; if ( ! json ) { bpfree ( buffer ) ; return NULL ; } if ( ! BP_JSONParseFromBuffer ( json , buffer , extra_info . file_size , max_depth_for_token_allocation , max_tokens_total ) ) { bpfree ( buffer ) ; BP_JSONDestroy ( json ) ; return NULL ; } bpfree ( buffer ) ; return json ; }
Attempts to create JSON from a file.
Attempts to create JSON from a file .
// ensure we have a filename // create extra info // retrieve file contents // allocate new buffer // attempt to parse from buffer // destroy the parse buffer before returning // return the new json structure if parsed OK!