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() ); }
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 TorrentBase::skip_value() { char c; if (m_buffer.pos() >= m_buffer.m_len) return seterror("expected value, found eof"); c = m_buffer.m_data[m_buffer.pos()]; if (c >= '0' && c <= '9') return skip_string(); if (c == 'i') return skip_number(); if (c == 'l') return skip_list(); if (c == 'd') return skip_dict(); return seterror("expected value"); }
void muj_phase1_value_number(muj_source source, muj_compressed_json target) { skip_number(source, target); }
void process_property(LibHalContext *hal_ctx, char *buf, lh_prop_t **prop) { char *s, *s1; char *key, *s_val = NULL; lh_prop_t *p; unsigned len; int remove = 0; s = skip_space(buf); if (*s == '-') { remove = 1; s = skip_space(s + 1); } if ((s1 = skip_number(s), s1 != s) && *s1 == ':') s = skip_space(s1 + 1); s = skip_non_eq_or_space(key = s); *s++ = 0; if (!*key) return; if (*key == '#') return; if (*s == '=') s++; s = skip_space(s); if (!*s) remove = 1; p = calloc(1, sizeof *p); p->type = LIBHAL_PROPERTY_TYPE_INVALID; p->key = strdup(key); if (remove) { p->next = *prop; *prop = p; return; } if (*s == '\'') { s_val = s + 1; s = strrchr(s_val, '\''); *(s ? s : s_val) = 0; p->type = LIBHAL_PROPERTY_TYPE_STRING; p->v.str_value = strdup(s_val); } else if (*s == '{') { s_val = s + 1; s1 = strrchr(s_val, '}'); if (s1) *s1 = 0; p->type = LIBHAL_PROPERTY_TYPE_STRLIST; len = 0; p->v.strlist_value = calloc(1, sizeof *p->v.strlist_value); while (*s_val++ == '\'') { s = skip_nonquote(s_val); if (*s) *s++ = 0; p->v.strlist_value = realloc(p->v.strlist_value, (len + 2) * sizeof *p->v.strlist_value); p->v.strlist_value[len] = strdup(s_val); p->v.strlist_value[++len] = NULL; s_val = skip_nonquote(s); } } else if (!strncmp(s, "true", 4)) { s += 4; p->type = LIBHAL_PROPERTY_TYPE_BOOLEAN; p->v.bool_value = TRUE; } else if (!strncmp(s, "false", 5)) { s += 5; p->type = LIBHAL_PROPERTY_TYPE_BOOLEAN; p->v.bool_value = FALSE; } else if ((s1 = skip_number(s)) != s) { if (strstr(s1, "(int)")) { *s1++ = 0; p->type = LIBHAL_PROPERTY_TYPE_INT32; p->v.int_value = strtol(s, NULL, 10); } else if (strstr(s1, "(uint64)")) { *s1++ = 0; p->type = LIBHAL_PROPERTY_TYPE_UINT64; p->v.uint64_value = strtoull(s, NULL, 10); } else if (strstr(s1, "(double)")) { p->type = LIBHAL_PROPERTY_TYPE_DOUBLE; p->v.double_value = strtod(s, NULL); } s = s1; } if (p->type == LIBHAL_PROPERTY_TYPE_INVALID) { free(p->key); free(p); } else { p->next = *prop; *prop = p; } }