void JsonIn::skip_value() { char ch; eat_whitespace(); ch = peek(); // it's either a string '"' if (ch == '"') { skip_string(); // or an object '{' } else if (ch == '{') { skip_object(); // or an array '[' } else if (ch == '[') { skip_array(); // or a number (-0123456789) } else if (ch == '-' || (ch >= '0' && ch <= '9')) { skip_number(); // or "true", "false" or "null" } else if (ch == 't') { skip_true(); } else if (ch == 'f') { skip_false(); } else if (ch == 'n') { skip_null(); // or an error. } else { std::stringstream err; err << "expected JSON value but got '" << ch << "'"; error(err.str()); } // skip_* end value automatically }
bool JsonIn::skip_value() { char ch; bool foundsep; eat_whitespace(); ch = peek(); // it's either a string '"' if (ch == '"') { foundsep = skip_string(); // or an object '{' } else if (ch == '{') { foundsep = skip_object(); // or an array '[' } else if (ch == '[') { foundsep = skip_array(); // or a number (-0123456789) } else if (ch == '-' || (ch >= '0' && ch <= '9')) { foundsep = skip_number(); // or "true", "false" or "null" } else if (ch == 't') { foundsep = skip_true(); } else if (ch == 'f') { foundsep = skip_false(); } else if (ch == 'n') { foundsep = skip_null(); // or an error. } else { std::stringstream err; err << line_number() << ": expected JSON value but got '" << ch << "'"; throw err.str(); } return foundsep;//b( foundsep || skip_separator() ); }
/******************************************************************** * FUNCTION parse_top * * Parse, and fill one val_value_t struct * * Error messages are printed by this function!! * Do not duplicate error messages upon error return * * * INPUTS: * tkc == token chain * val == value iniitalized and could be already filled in * keepvals == TRUE to save existing values in 'val', as needed * FALSE to overwrite old values in 'val', as needed * * RETURNS: * status of the operation *********************************************************************/ static status_t parse_top (tk_chain_t *tkc, val_value_t *val, boolean keepvals) { status_t res; boolean done; res = NO_ERR; /* get the container name */ done = FALSE; while (!done) { res = match_name(tkc, obj_get_name(val->obj)); if (res == ERR_NCX_EOF) { if (LOGDEBUG) { log_debug("\nconf: object '%s' not found in file '%s'", obj_get_name(val->obj), tkc->filename); } return NO_ERR; } else if (res != NO_ERR) { res = skip_object(tkc); if (res != NO_ERR) { return res; } } else { done = TRUE; } } /* get a left brace */ res = consume_tk(tkc, TK_TT_LBRACE); if (res != NO_ERR) { ncx_conf_exp_err(tkc, res, "left brace to start object"); return res; } done = FALSE; while (!done) { res = get_tk(tkc); if (res == ERR_NCX_EOF) { return NO_ERR; } else if (res != NO_ERR) { return res; } /* allow an empty parmset */ if (TK_CUR_TYP(tkc)==TK_TT_RBRACE) { done = TRUE; } else { res = parse_parm(tkc, val, keepvals); if (res != NO_ERR) { done = TRUE; } } } return res; } /* parse_top */