library/src/javascript/JSON/BP-LibJSMN.cc
/**
 * Fills next available token with JSON primitive.
 */
Fills next available token with JSON primitive.
Fills next available token with JSON primitive .
static int jsmn_parse_primitive
(
	P_BP_JSON    json,
	jsmn_parser *parser,
	const char *js,
	size_t len,
	jsmntok_t *tokens,
	size_t num_tokens
)
{
	jsmntok_t *token = NULL;
	int start = 0;
	start = parser->pos;
	for
	(
		;
		parser->pos < len && js[parser->pos] != '\0';
		parser->pos++
	)
	{
		switch (js[parser->pos])
		{
			case '\t':
			case '\r':
			case '\n':
			case ' ':
			case ',':
			case ']':
			case '}':
				goto found;
		}
		if
		(
			js[parser->pos] < 32 || js[parser->pos] >= 127
		)
		{
			char tmp_err_buff[512];
			BP_ZERO_STACK(tmp_err_buff);
			sprintf((char *) &tmp_err_buff, "jsmn_parse_primitive() reports that an invalid character \\x%.02x (%c) was found within the json buffer at byte-position: %u.",js[parser->pos], js[parser->pos], parser->pos);
			BP_JSONParseAddErrorMsg(json, NULL, (char *) &tmp_err_buff);
			parser->pos = start;
			return JSMN_ERROR_INVAL;
		}
	}
	parser->pos = start;
	BP_JSONParseAddErrorMsg(json, NULL, "jsmn_parse_primitive() reports that the JSON provided was 'too short'.  This meaning that the json was parsing fine, except the buffer ended prematurely with regards to parse logic.");
	return JSMN_ERROR_PART;
found:
	if (tokens == NULL)
	{
		parser->pos--;
		return 0;
	}
	token = jsmn_alloc_token(json, parser, tokens, num_tokens);
	if (!token)
	{
		parser->pos = start;
		BP_JSONParseAddErrorMsg(json, NULL, "Parser indicates that we've run out of memory.");
		return JSMN_ERROR_NOMEM;
	}
	jsmn_fill_token(json, token, JSMN_PRIMITIVE, start, parser->pos);
	token->parent = parser->toksuper;
	parser->pos--;
	return 0;
}
static int jsmn_parse_primitive ( P_BP_JSON json , jsmn_parser * parser , const char * js , size_t len , jsmntok_t * tokens , size_t num_tokens ) { jsmntok_t * token = NULL ; int start = 0 ; start = parser -> pos ; for ( ; parser -> pos < len && js [ parser -> pos ] != ' \0 ' ; parser -> pos ++ ) { switch ( js [ parser -> pos ] ) { case ' \t ' : case ' \r ' : case ' \n ' : case ' ' : case ' ' : case ' ' : case ' ' : goto found ; } if ( js [ parser -> pos ] < 32 || js [ parser -> pos ] >= 127 ) { char tmp_err_buff [ 512 ] ; BP_ZERO_STACK ( tmp_err_buff ) ; sprintf ( ( char * ) & tmp_err_buff , " \\ " , js [ parser -> pos ] , js [ parser -> pos ] , parser -> pos ) ; BP_JSONParseAddErrorMsg ( json , NULL , ( char * ) & tmp_err_buff ) ; parser -> pos = start ; return JSMN_ERROR_INVAL ; } } parser -> pos = start ; BP_JSONParseAddErrorMsg ( json , NULL , " " ) ; return JSMN_ERROR_PART ; found : if ( tokens == NULL ) { parser -> pos -- ; return 0 ; } token = jsmn_alloc_token ( json , parser , tokens , num_tokens ) ; if ( ! token ) { parser -> pos = start ; BP_JSONParseAddErrorMsg ( json , NULL , " " ) ; return JSMN_ERROR_NOMEM ; } jsmn_fill_token ( json , token , JSMN_PRIMITIVE , start , parser -> pos ) ; token -> parent = parser -> toksuper ; parser -> pos -- ; return 0 ; }
Fills next available token with JSON primitive.
Fills next available token with JSON primitive .
// switch on current character // create a small temporary stack buffer // convert values for output // add the error message /* In strict mode primitive must be followed by a comma/object/array */ // add the error message // token was found to be acceptable // attempt to allocate token