json_object_table->count);
lh_foreach(json_object_table, ent)
{
- struct json_object* obj = (struct json_object*)lh_entry_v(ent);
- MC_DEBUG("\t%s:%p\n", json_type_to_name(obj->o_type), obj);
+ struct json_object* obj =
+ (struct json_object*) lh_entry_v(ent);
+ MC_DEBUG("\t%s:%p\n",
+ json_type_to_name(obj->o_type), obj);
}
}
}
if(c < ' ')
{
if(pos - start_offset > 0)
- printbuf_memappend(pb, str + start_offset, pos - start_offset);
+ printbuf_memappend(pb,
+ str + start_offset,
+ pos - start_offset);
sprintbuf(pb, "\\u00%c%c",
json_hex_chars[c >> 4],
json_hex_chars[c & 0xf]);
{
if (jso)
jso->_ref_count++;
- return jso;
+ return NULL;
}
int json_object_put(struct json_object *jso)
static int json_object_object_to_json_string(struct json_object* jso,
struct printbuf *pb,
int level,
- int flags)
+ int flags)
{
int had_children = 0;
struct json_object_iter iter;
jso->_delete = &json_object_object_delete;
jso->_to_json_string = &json_object_object_to_json_string;
jso->o.c_object = lh_kchar_table_new(JSON_OBJECT_DEF_HASH_ENTRIES,
- &json_object_lh_entry_free);
+ &json_object_lh_entry_free);
if (!jso->o.c_object)
{
json_object_generic_delete(jso);
struct lh_entry *existing_entry;
const unsigned long hash = lh_get_hash(jso->o.c_object, (const void *)key);
existing_entry = (opts & JSON_C_OBJECT_ADD_KEY_IS_NEW) ? NULL :
- lh_table_lookup_entry_w_hash(jso->o.c_object, (const void *)key, hash);
+ lh_table_lookup_entry_w_hash(jso->o.c_object,
+ (const void *)key, hash);
if (!existing_entry)
{
const void *const k = (opts & JSON_C_OBJECT_KEY_IS_CONSTANT) ?
lh_table_insert_w_hash(jso->o.c_object, k, val, hash, opts);
return;
}
- existing_value = (json_object *)lh_entry_v(existing_entry);
+ existing_value = (json_object *) lh_entry_v(existing_entry);
if (existing_value)
json_object_put(existing_value);
existing_entry->v = val;
}
int json_object_object_add(struct json_object* jso, const char *key,
- struct json_object *val)
+ struct json_object *val)
{
// We lookup the entry and replace the value, rather than just deleting
// and re-adding it, so the existing key remains valid.
json_object *existing_value = NULL;
struct lh_entry *existing_entry;
const unsigned long hash = lh_get_hash(jso->o.c_object, (const void *)key);
- existing_entry = lh_table_lookup_entry_w_hash(jso->o.c_object, (const void *)key, hash);
+ existing_entry = lh_table_lookup_entry_w_hash(jso->o.c_object,
+ (const void *)key, hash);
if (!existing_entry)
{
char *keydup = strdup(key);
return lh_table_length(jso->o.c_object);
}
-struct json_object* json_object_object_get(const struct json_object* jso, const char *key)
+struct json_object* json_object_object_get(const struct json_object* jso,
+ const char *key)
{
struct json_object *result = NULL;
json_object_object_get_ex(jso, key, &result);
return result;
}
-json_bool json_object_object_get_ex(const struct json_object* jso, const char *key, struct json_object **value)
+json_bool json_object_object_get_ex(const struct json_object* jso, const char *key,
+ struct json_object **value)
{
if (value != NULL)
*value = NULL;
switch(jso->o_type)
{
case json_type_object:
- return lh_table_lookup_ex(jso->o.c_object, (const void *)key, (void**)value);
+ return lh_table_lookup_ex(jso->o.c_object, (const void *) key,
+ (void**) value);
default:
if (value != NULL)
*value = NULL;
static int json_object_boolean_to_json_string(struct json_object* jso,
struct printbuf *pb,
int level,
- int flags)
+ int flags)
{
if (jso->o.c_boolean)
return sprintbuf(pb, "true");
- else
- return sprintbuf(pb, "false");
+ return sprintbuf(pb, "false");
}
struct json_object* json_object_new_boolean(json_bool b)
/* Make sure we return the correct values for out of range numbers. */
if (cint64 <= INT32_MIN)
return INT32_MIN;
- else if (cint64 >= INT32_MAX)
+ if (cint64 >= INT32_MAX)
return INT32_MAX;
- else
- return (int32_t)cint64;
+ return (int32_t) cint64;
case json_type_double:
return (int32_t)jso->o.c_double;
case json_type_boolean:
static int json_object_string_to_json_string(struct json_object* jso,
struct printbuf *pb,
int level,
- int flags)
+ int flags)
{
sprintbuf(pb, "\"");
json_escape_str(pb, get_string_component(jso), jso->o.c_string.len, flags);
if (flags & JSON_C_TO_STRING_SPACED)
return sprintbuf(pb, " ]");
- else
- return sprintbuf(pb, "]");
+ return sprintbuf(pb, "]");
}
static void json_object_array_entry_free(void *data)
}
}
-void json_object_array_sort(struct json_object *jso, int(*sort_fn)(const void *, const void *))
+void json_object_array_sort(struct json_object *jso,
+ int(*sort_fn)(const void *, const void *))
{
array_list_sort(jso->o.c_array, sort_fn);
}
const char *json_tokener_error_desc(enum json_tokener_error jerr)
{
- int jerr_int = (int)jerr;
- if (jerr_int < 0 || jerr_int >= (int)(sizeof(json_tokener_errors) / sizeof(json_tokener_errors[0])))
- return "Unknown error, invalid json_tokener_error value passed to json_tokener_error_desc()";
+ int jerr_int = (int) jerr;
+ if (jerr_int < 0 ||
+ jerr_int >= (int)(sizeof(json_tokener_errors) / sizeof(json_tokener_errors[0])))
+ return "Unknown error, "
+ "invalid json_tokener_error value passed to json_tokener_error_desc()";
return json_tokener_errors[jerr];
}
tok = (struct json_tokener*)calloc(1, sizeof(struct json_tokener));
if (!tok) return NULL;
- tok->stack = (struct json_tokener_srec *)calloc(depth, sizeof(struct json_tokener_srec));
+ tok->stack = (struct json_tokener_srec *) calloc(depth,
+ sizeof(struct json_tokener_srec));
if (!tok->stack) {
free(tok);
return NULL;
return obj;
}
-struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokener_error *error)
+struct json_object* json_tokener_parse_verbose(const char *str,
+ enum json_tokener_error *error)
{
struct json_tokener* tok;
struct json_object* obj;
* Returns 1 on success, sets tok->err and returns 0 if no more chars.
* Implicit inputs: str, len vars
*/
-#define PEEK_CHAR(dest, tok) \
- (((tok)->char_offset == len) ? \
- (((tok)->depth == 0 && state == json_tokener_state_eatws && saved_state == json_tokener_state_finish) ? \
- (((tok)->err = json_tokener_success), 0) \
- : \
- (((tok)->err = json_tokener_continue), 0) \
- ) : \
- (((dest) = *str), 1) \
+#define PEEK_CHAR(dest, tok) \
+ (((tok)->char_offset == len) ? \
+ (((tok)->depth == 0 && \
+ state == json_tokener_state_eatws && \
+ saved_state == json_tokener_state_finish \
+ ) ? \
+ (((tok)->err = json_tokener_success), 0) \
+ : \
+ (((tok)->err = json_tokener_continue), 0) \
+ ) : \
+ (((dest) = *str), 1) \
)
/* ADVANCE_CHAR() macro:
printbuf_reset(tok->pb);
tok->st_pos = 0;
goto redo_char;
-#if defined(__GNUC__)
- case '0' ... '9':
-#else
- case '0':
+ case '0':
case '1':
case '2':
case '3':
case '7':
case '8':
case '9':
-#endif
case '-':
state = json_tokener_state_number;
printbuf_reset(tok->pb);
{
if (tok->st_pos == json_inf_str_len)
{
- current = json_object_new_double(is_negative ? -INFINITY : INFINITY);
+ current = json_object_new_double(is_negative
+ ? -INFINITY : INFINITY);
if(current == NULL)
goto out;
saved_state = json_tokener_state_finish;
* characters.
*/
if( !ADVANCE_CHAR(str, tok) || !ADVANCE_CHAR(str, tok) ) {
- printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
- }
+ printbuf_memappend_fast(tok->pb,
+ (char*) utf8_replacement_char, 3);
+ }
/* Advance to the first char of the next sequence and
* continue processing with the next sequence.
*/
if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok)) {
- printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
+ printbuf_memappend_fast(tok->pb,
+ (char*) utf8_replacement_char, 3);
goto out;
}
tok->ucs_char = 0;
* it. Put a replacement char in for the hi surrogate
* and pretend we finished.
*/
- printbuf_memappend_fast(tok->pb, (char*)utf8_replacement_char, 3);
+ printbuf_memappend_fast(tok->pb,
+ (char*) utf8_replacement_char, 3);
}
} else if (IS_LOW_SURROGATE(tok->ucs_char)) {
/* Got a low surrogate not preceded by a high */
int64_t num64;
double numd;
if (!tok->is_double && json_parse_int64(tok->pb->buf, &num64) == 0) {
- if (num64 && tok->pb->buf[0]=='0' && (tok->flags & JSON_TOKENER_STRICT)) {
+ if (num64 && tok->pb->buf[0]=='0' &&
+ (tok->flags & JSON_TOKENER_STRICT)) {
/* in strict mode, number must not start with 0 */
tok->err = json_tokener_error_parse_number;
goto out;
case json_tokener_state_array_after_sep:
case json_tokener_state_array:
if(c == ']') {
- if (state == json_tokener_state_array_after_sep &&
- (tok->flags & JSON_TOKENER_STRICT))
- {
- tok->err = json_tokener_error_parse_unexpected;
- goto out;
- }
+ if (state == json_tokener_state_array_after_sep &&
+ (tok->flags & JSON_TOKENER_STRICT))
+ {
+ tok->err = json_tokener_error_parse_unexpected;
+ goto out;
+ }
saved_state = json_tokener_state_finish;
state = json_tokener_state_eatws;
} else {
void json_tokener_set_flags(struct json_tokener *tok, int flags)
{
- tok->flags = flags;
+ if(tok) tok->flags = flags;
}