mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
make style
This commit is contained in:
parent
0d9223a547
commit
0373696662
483 changed files with 56514 additions and 52451 deletions
|
@ -51,7 +51,7 @@ extern volatile uint32_t hashtable_seed;
|
|||
json_t *json_object(void)
|
||||
{
|
||||
json_object_t *object = jsonp_malloc(sizeof(json_object_t));
|
||||
if(!object)
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
if (!hashtable_seed) {
|
||||
|
@ -61,8 +61,7 @@ json_t *json_object(void)
|
|||
|
||||
json_init(&object->json, JSON_OBJECT);
|
||||
|
||||
if(hashtable_init(&object->hashtable))
|
||||
{
|
||||
if (hashtable_init(&object->hashtable)) {
|
||||
jsonp_free(object);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -80,7 +79,7 @@ size_t json_object_size(const json_t *json)
|
|||
{
|
||||
json_object_t *object;
|
||||
|
||||
if(!json_is_object(json))
|
||||
if (!json_is_object(json))
|
||||
return 0;
|
||||
|
||||
object = json_to_object(json);
|
||||
|
@ -91,7 +90,7 @@ json_t *json_object_get(const json_t *json, const char *key)
|
|||
{
|
||||
json_object_t *object;
|
||||
|
||||
if(!key || !json_is_object(json))
|
||||
if (!key || !json_is_object(json))
|
||||
return NULL;
|
||||
|
||||
object = json_to_object(json);
|
||||
|
@ -102,18 +101,16 @@ int json_object_set_new_nocheck(json_t *json, const char *key, json_t *value)
|
|||
{
|
||||
json_object_t *object;
|
||||
|
||||
if(!value)
|
||||
if (!value)
|
||||
return -1;
|
||||
|
||||
if(!key || !json_is_object(json) || json == value)
|
||||
{
|
||||
if (!key || !json_is_object(json) || json == value) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
}
|
||||
object = json_to_object(json);
|
||||
|
||||
if(hashtable_set(&object->hashtable, key, value))
|
||||
{
|
||||
if (hashtable_set(&object->hashtable, key, value)) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
}
|
||||
|
@ -123,8 +120,7 @@ int json_object_set_new_nocheck(json_t *json, const char *key, json_t *value)
|
|||
|
||||
int json_object_set_new(json_t *json, const char *key, json_t *value)
|
||||
{
|
||||
if(!key || !utf8_check_string(key, strlen(key)))
|
||||
{
|
||||
if (!key || !utf8_check_string(key, strlen(key))) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
}
|
||||
|
@ -136,7 +132,7 @@ int json_object_del(json_t *json, const char *key)
|
|||
{
|
||||
json_object_t *object;
|
||||
|
||||
if(!key || !json_is_object(json))
|
||||
if (!key || !json_is_object(json))
|
||||
return -1;
|
||||
|
||||
object = json_to_object(json);
|
||||
|
@ -147,7 +143,7 @@ int json_object_clear(json_t *json)
|
|||
{
|
||||
json_object_t *object;
|
||||
|
||||
if(!json_is_object(json))
|
||||
if (!json_is_object(json))
|
||||
return -1;
|
||||
|
||||
object = json_to_object(json);
|
||||
|
@ -161,11 +157,11 @@ int json_object_update(json_t *object, json_t *other)
|
|||
const char *key;
|
||||
json_t *value;
|
||||
|
||||
if(!json_is_object(object) || !json_is_object(other))
|
||||
if (!json_is_object(object) || !json_is_object(other))
|
||||
return -1;
|
||||
|
||||
json_object_foreach(other, key, value) {
|
||||
if(json_object_set_nocheck(object, key, value))
|
||||
if (json_object_set_nocheck(object, key, value))
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -177,11 +173,11 @@ int json_object_update_existing(json_t *object, json_t *other)
|
|||
const char *key;
|
||||
json_t *value;
|
||||
|
||||
if(!json_is_object(object) || !json_is_object(other))
|
||||
if (!json_is_object(object) || !json_is_object(other))
|
||||
return -1;
|
||||
|
||||
json_object_foreach(other, key, value) {
|
||||
if(json_object_get(object, key))
|
||||
if (json_object_get(object, key))
|
||||
json_object_set_nocheck(object, key, value);
|
||||
}
|
||||
|
||||
|
@ -193,11 +189,11 @@ int json_object_update_missing(json_t *object, json_t *other)
|
|||
const char *key;
|
||||
json_t *value;
|
||||
|
||||
if(!json_is_object(object) || !json_is_object(other))
|
||||
if (!json_is_object(object) || !json_is_object(other))
|
||||
return -1;
|
||||
|
||||
json_object_foreach(other, key, value) {
|
||||
if(!json_object_get(object, key))
|
||||
if (!json_object_get(object, key))
|
||||
json_object_set_nocheck(object, key, value);
|
||||
}
|
||||
|
||||
|
@ -208,7 +204,7 @@ void *json_object_iter(json_t *json)
|
|||
{
|
||||
json_object_t *object;
|
||||
|
||||
if(!json_is_object(json))
|
||||
if (!json_is_object(json))
|
||||
return NULL;
|
||||
|
||||
object = json_to_object(json);
|
||||
|
@ -219,7 +215,7 @@ void *json_object_iter_at(json_t *json, const char *key)
|
|||
{
|
||||
json_object_t *object;
|
||||
|
||||
if(!key || !json_is_object(json))
|
||||
if (!key || !json_is_object(json))
|
||||
return NULL;
|
||||
|
||||
object = json_to_object(json);
|
||||
|
@ -230,7 +226,7 @@ void *json_object_iter_next(json_t *json, void *iter)
|
|||
{
|
||||
json_object_t *object;
|
||||
|
||||
if(!json_is_object(json) || iter == NULL)
|
||||
if (!json_is_object(json) || iter == NULL)
|
||||
return NULL;
|
||||
|
||||
object = json_to_object(json);
|
||||
|
@ -239,7 +235,7 @@ void *json_object_iter_next(json_t *json, void *iter)
|
|||
|
||||
const char *json_object_iter_key(void *iter)
|
||||
{
|
||||
if(!iter)
|
||||
if (!iter)
|
||||
return NULL;
|
||||
|
||||
return hashtable_iter_key(iter);
|
||||
|
@ -247,7 +243,7 @@ const char *json_object_iter_key(void *iter)
|
|||
|
||||
json_t *json_object_iter_value(void *iter)
|
||||
{
|
||||
if(!iter)
|
||||
if (!iter)
|
||||
return NULL;
|
||||
|
||||
return (json_t *)hashtable_iter_value(iter);
|
||||
|
@ -255,8 +251,7 @@ json_t *json_object_iter_value(void *iter)
|
|||
|
||||
int json_object_iter_set_new(json_t *json, void *iter, json_t *value)
|
||||
{
|
||||
if(!json_is_object(json) || !iter || !value)
|
||||
{
|
||||
if (!json_is_object(json) || !iter || !value) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
}
|
||||
|
@ -267,7 +262,7 @@ int json_object_iter_set_new(json_t *json, void *iter, json_t *value)
|
|||
|
||||
void *json_object_key_to_iter(const char *key)
|
||||
{
|
||||
if(!key)
|
||||
if (!key)
|
||||
return NULL;
|
||||
|
||||
return hashtable_key_to_iter(key);
|
||||
|
@ -278,13 +273,13 @@ static int json_object_equal(const json_t *object1, const json_t *object2)
|
|||
const char *key;
|
||||
const json_t *value1, *value2;
|
||||
|
||||
if(json_object_size(object1) != json_object_size(object2))
|
||||
if (json_object_size(object1) != json_object_size(object2))
|
||||
return 0;
|
||||
|
||||
json_object_foreach((json_t *)object1, key, value1) {
|
||||
value2 = json_object_get(object2, key);
|
||||
|
||||
if(!json_equal(value1, value2))
|
||||
if (!json_equal(value1, value2))
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -299,11 +294,11 @@ static json_t *json_object_copy(json_t *object)
|
|||
json_t *value;
|
||||
|
||||
result = json_object();
|
||||
if(!result)
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
json_object_foreach(object, key, value)
|
||||
json_object_set_nocheck(result, key, value);
|
||||
json_object_set_nocheck(result, key, value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -314,13 +309,13 @@ static json_t *json_object_deep_copy(const json_t *object)
|
|||
void *iter;
|
||||
|
||||
result = json_object();
|
||||
if(!result)
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
/* Cannot use json_object_foreach because object has to be cast
|
||||
non-const */
|
||||
iter = json_object_iter((json_t *)object);
|
||||
while(iter) {
|
||||
while (iter) {
|
||||
const char *key;
|
||||
const json_t *value;
|
||||
key = json_object_iter_key(iter);
|
||||
|
@ -339,7 +334,7 @@ static json_t *json_object_deep_copy(const json_t *object)
|
|||
json_t *json_array(void)
|
||||
{
|
||||
json_array_t *array = jsonp_malloc(sizeof(json_array_t));
|
||||
if(!array)
|
||||
if (!array)
|
||||
return NULL;
|
||||
json_init(&array->json, JSON_ARRAY);
|
||||
|
||||
|
@ -347,7 +342,7 @@ json_t *json_array(void)
|
|||
array->size = 8;
|
||||
|
||||
array->table = jsonp_malloc(array->size * sizeof(json_t *));
|
||||
if(!array->table) {
|
||||
if (!array->table) {
|
||||
jsonp_free(array);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -359,7 +354,7 @@ static void json_delete_array(json_array_t *array)
|
|||
{
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < array->entries; i++)
|
||||
for (i = 0; i < array->entries; i++)
|
||||
json_decref(array->table[i]);
|
||||
|
||||
jsonp_free(array->table);
|
||||
|
@ -368,7 +363,7 @@ static void json_delete_array(json_array_t *array)
|
|||
|
||||
size_t json_array_size(const json_t *json)
|
||||
{
|
||||
if(!json_is_array(json))
|
||||
if (!json_is_array(json))
|
||||
return 0;
|
||||
|
||||
return json_to_array(json)->entries;
|
||||
|
@ -377,11 +372,11 @@ size_t json_array_size(const json_t *json)
|
|||
json_t *json_array_get(const json_t *json, size_t index)
|
||||
{
|
||||
json_array_t *array;
|
||||
if(!json_is_array(json))
|
||||
if (!json_is_array(json))
|
||||
return NULL;
|
||||
array = json_to_array(json);
|
||||
|
||||
if(index >= array->entries)
|
||||
if (index >= array->entries)
|
||||
return NULL;
|
||||
|
||||
return array->table[index];
|
||||
|
@ -391,18 +386,16 @@ int json_array_set_new(json_t *json, size_t index, json_t *value)
|
|||
{
|
||||
json_array_t *array;
|
||||
|
||||
if(!value)
|
||||
if (!value)
|
||||
return -1;
|
||||
|
||||
if(!json_is_array(json) || json == value)
|
||||
{
|
||||
if (!json_is_array(json) || json == value) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
}
|
||||
array = json_to_array(json);
|
||||
|
||||
if(index >= array->entries)
|
||||
{
|
||||
if (index >= array->entries) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
}
|
||||
|
@ -433,20 +426,20 @@ static json_t **json_array_grow(json_array_t *array,
|
|||
size_t new_size;
|
||||
json_t **old_table, **new_table;
|
||||
|
||||
if(array->entries + amount <= array->size)
|
||||
if (array->entries + amount <= array->size)
|
||||
return array->table;
|
||||
|
||||
old_table = array->table;
|
||||
|
||||
new_size = max(array->size + amount, array->size * 2);
|
||||
new_table = jsonp_malloc(new_size * sizeof(json_t *));
|
||||
if(!new_table)
|
||||
if (!new_table)
|
||||
return NULL;
|
||||
|
||||
array->size = new_size;
|
||||
array->table = new_table;
|
||||
|
||||
if(copy) {
|
||||
if (copy) {
|
||||
array_copy(array->table, 0, old_table, 0, array->entries);
|
||||
jsonp_free(old_table);
|
||||
return array->table;
|
||||
|
@ -459,17 +452,16 @@ int json_array_append_new(json_t *json, json_t *value)
|
|||
{
|
||||
json_array_t *array;
|
||||
|
||||
if(!value)
|
||||
if (!value)
|
||||
return -1;
|
||||
|
||||
if(!json_is_array(json) || json == value)
|
||||
{
|
||||
if (!json_is_array(json) || json == value) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
}
|
||||
array = json_to_array(json);
|
||||
|
||||
if(!json_array_grow(array, 1, 1)) {
|
||||
if (!json_array_grow(array, 1, 1)) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
}
|
||||
|
@ -485,33 +477,32 @@ int json_array_insert_new(json_t *json, size_t index, json_t *value)
|
|||
json_array_t *array;
|
||||
json_t **old_table;
|
||||
|
||||
if(!value)
|
||||
if (!value)
|
||||
return -1;
|
||||
|
||||
if(!json_is_array(json) || json == value) {
|
||||
if (!json_is_array(json) || json == value) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
}
|
||||
array = json_to_array(json);
|
||||
|
||||
if(index > array->entries) {
|
||||
if (index > array->entries) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
}
|
||||
|
||||
old_table = json_array_grow(array, 1, 0);
|
||||
if(!old_table) {
|
||||
if (!old_table) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(old_table != array->table) {
|
||||
if (old_table != array->table) {
|
||||
array_copy(array->table, 0, old_table, 0, index);
|
||||
array_copy(array->table, index + 1, old_table, index,
|
||||
array->entries - index);
|
||||
jsonp_free(old_table);
|
||||
}
|
||||
else
|
||||
} else
|
||||
array_move(array, index + 1, index, array->entries - index);
|
||||
|
||||
array->table[index] = value;
|
||||
|
@ -524,17 +515,17 @@ int json_array_remove(json_t *json, size_t index)
|
|||
{
|
||||
json_array_t *array;
|
||||
|
||||
if(!json_is_array(json))
|
||||
if (!json_is_array(json))
|
||||
return -1;
|
||||
array = json_to_array(json);
|
||||
|
||||
if(index >= array->entries)
|
||||
if (index >= array->entries)
|
||||
return -1;
|
||||
|
||||
json_decref(array->table[index]);
|
||||
|
||||
/* If we're removing the last element, nothing has to be moved */
|
||||
if(index < array->entries - 1)
|
||||
if (index < array->entries - 1)
|
||||
array_move(array, index, index + 1, array->entries - index - 1);
|
||||
|
||||
array->entries--;
|
||||
|
@ -547,11 +538,11 @@ int json_array_clear(json_t *json)
|
|||
json_array_t *array;
|
||||
size_t i;
|
||||
|
||||
if(!json_is_array(json))
|
||||
if (!json_is_array(json))
|
||||
return -1;
|
||||
array = json_to_array(json);
|
||||
|
||||
for(i = 0; i < array->entries; i++)
|
||||
for (i = 0; i < array->entries; i++)
|
||||
json_decref(array->table[i]);
|
||||
|
||||
array->entries = 0;
|
||||
|
@ -563,15 +554,15 @@ int json_array_extend(json_t *json, json_t *other_json)
|
|||
json_array_t *array, *other;
|
||||
size_t i;
|
||||
|
||||
if(!json_is_array(json) || !json_is_array(other_json))
|
||||
if (!json_is_array(json) || !json_is_array(other_json))
|
||||
return -1;
|
||||
array = json_to_array(json);
|
||||
other = json_to_array(other_json);
|
||||
|
||||
if(!json_array_grow(array, other->entries, 1))
|
||||
if (!json_array_grow(array, other->entries, 1))
|
||||
return -1;
|
||||
|
||||
for(i = 0; i < other->entries; i++)
|
||||
for (i = 0; i < other->entries; i++)
|
||||
json_incref(other->table[i]);
|
||||
|
||||
array_copy(array->table, array->entries, other->table, 0, other->entries);
|
||||
|
@ -585,17 +576,16 @@ static int json_array_equal(const json_t *array1, const json_t *array2)
|
|||
size_t i, size;
|
||||
|
||||
size = json_array_size(array1);
|
||||
if(size != json_array_size(array2))
|
||||
if (size != json_array_size(array2))
|
||||
return 0;
|
||||
|
||||
for(i = 0; i < size; i++)
|
||||
{
|
||||
for (i = 0; i < size; i++) {
|
||||
json_t *value1, *value2;
|
||||
|
||||
value1 = json_array_get(array1, i);
|
||||
value2 = json_array_get(array2, i);
|
||||
|
||||
if(!json_equal(value1, value2))
|
||||
if (!json_equal(value1, value2))
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -608,10 +598,10 @@ static json_t *json_array_copy(json_t *array)
|
|||
size_t i;
|
||||
|
||||
result = json_array();
|
||||
if(!result)
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < json_array_size(array); i++)
|
||||
for (i = 0; i < json_array_size(array); i++)
|
||||
json_array_append(result, json_array_get(array, i));
|
||||
|
||||
return result;
|
||||
|
@ -623,10 +613,10 @@ static json_t *json_array_deep_copy(const json_t *array)
|
|||
size_t i;
|
||||
|
||||
result = json_array();
|
||||
if(!result)
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < json_array_size(array); i++)
|
||||
for (i = 0; i < json_array_size(array); i++)
|
||||
json_array_append_new(result, json_deep_copy(json_array_get(array, i)));
|
||||
|
||||
return result;
|
||||
|
@ -639,19 +629,19 @@ static json_t *string_create(const char *value, size_t len, int own)
|
|||
char *v;
|
||||
json_string_t *string;
|
||||
|
||||
if(!value)
|
||||
if (!value)
|
||||
return NULL;
|
||||
|
||||
if(own)
|
||||
if (own)
|
||||
v = (char *)value;
|
||||
else {
|
||||
v = jsonp_strndup(value, len);
|
||||
if(!v)
|
||||
if (!v)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
string = jsonp_malloc(sizeof(json_string_t));
|
||||
if(!string) {
|
||||
if (!string) {
|
||||
jsonp_free(v);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -664,7 +654,7 @@ static json_t *string_create(const char *value, size_t len, int own)
|
|||
|
||||
json_t *json_string_nocheck(const char *value)
|
||||
{
|
||||
if(!value)
|
||||
if (!value)
|
||||
return NULL;
|
||||
|
||||
return string_create(value, strlen(value), 0);
|
||||
|
@ -683,7 +673,7 @@ json_t *jsonp_stringn_nocheck_own(const char *value, size_t len)
|
|||
|
||||
json_t *json_string(const char *value)
|
||||
{
|
||||
if(!value)
|
||||
if (!value)
|
||||
return NULL;
|
||||
|
||||
return json_stringn(value, strlen(value));
|
||||
|
@ -691,7 +681,7 @@ json_t *json_string(const char *value)
|
|||
|
||||
json_t *json_stringn(const char *value, size_t len)
|
||||
{
|
||||
if(!value || !utf8_check_string(value, len))
|
||||
if (!value || !utf8_check_string(value, len))
|
||||
return NULL;
|
||||
|
||||
return json_stringn_nocheck(value, len);
|
||||
|
@ -699,7 +689,7 @@ json_t *json_stringn(const char *value, size_t len)
|
|||
|
||||
const char *json_string_value(const json_t *json)
|
||||
{
|
||||
if(!json_is_string(json))
|
||||
if (!json_is_string(json))
|
||||
return NULL;
|
||||
|
||||
return json_to_string(json)->value;
|
||||
|
@ -707,7 +697,7 @@ const char *json_string_value(const json_t *json)
|
|||
|
||||
size_t json_string_length(const json_t *json)
|
||||
{
|
||||
if(!json_is_string(json))
|
||||
if (!json_is_string(json))
|
||||
return 0;
|
||||
|
||||
return json_to_string(json)->length;
|
||||
|
@ -715,7 +705,7 @@ size_t json_string_length(const json_t *json)
|
|||
|
||||
int json_string_set_nocheck(json_t *json, const char *value)
|
||||
{
|
||||
if(!value)
|
||||
if (!value)
|
||||
return -1;
|
||||
|
||||
return json_string_setn_nocheck(json, value, strlen(value));
|
||||
|
@ -726,11 +716,11 @@ int json_string_setn_nocheck(json_t *json, const char *value, size_t len)
|
|||
char *dup;
|
||||
json_string_t *string;
|
||||
|
||||
if(!json_is_string(json) || !value)
|
||||
if (!json_is_string(json) || !value)
|
||||
return -1;
|
||||
|
||||
dup = jsonp_strndup(value, len);
|
||||
if(!dup)
|
||||
if (!dup)
|
||||
return -1;
|
||||
|
||||
string = json_to_string(json);
|
||||
|
@ -743,7 +733,7 @@ int json_string_setn_nocheck(json_t *json, const char *value, size_t len)
|
|||
|
||||
int json_string_set(json_t *json, const char *value)
|
||||
{
|
||||
if(!value)
|
||||
if (!value)
|
||||
return -1;
|
||||
|
||||
return json_string_setn(json, value, strlen(value));
|
||||
|
@ -751,7 +741,7 @@ int json_string_set(json_t *json, const char *value)
|
|||
|
||||
int json_string_setn(json_t *json, const char *value, size_t len)
|
||||
{
|
||||
if(!value || !utf8_check_string(value, len))
|
||||
if (!value || !utf8_check_string(value, len))
|
||||
return -1;
|
||||
|
||||
return json_string_setn_nocheck(json, value, len);
|
||||
|
@ -780,7 +770,8 @@ static json_t *json_string_copy(const json_t *string)
|
|||
return json_stringn_nocheck(s->value, s->length);
|
||||
}
|
||||
|
||||
json_t *json_vsprintf(const char *fmt, va_list ap) {
|
||||
json_t *json_vsprintf(const char *fmt, va_list ap)
|
||||
{
|
||||
json_t *json = NULL;
|
||||
int length;
|
||||
char *buf;
|
||||
|
@ -810,7 +801,8 @@ out:
|
|||
return json;
|
||||
}
|
||||
|
||||
json_t *json_sprintf(const char *fmt, ...) {
|
||||
json_t *json_sprintf(const char *fmt, ...)
|
||||
{
|
||||
json_t *result;
|
||||
va_list ap;
|
||||
|
||||
|
@ -827,7 +819,7 @@ json_t *json_sprintf(const char *fmt, ...) {
|
|||
json_t *json_integer(json_int_t value)
|
||||
{
|
||||
json_integer_t *integer = jsonp_malloc(sizeof(json_integer_t));
|
||||
if(!integer)
|
||||
if (!integer)
|
||||
return NULL;
|
||||
json_init(&integer->json, JSON_INTEGER);
|
||||
|
||||
|
@ -837,7 +829,7 @@ json_t *json_integer(json_int_t value)
|
|||
|
||||
json_int_t json_integer_value(const json_t *json)
|
||||
{
|
||||
if(!json_is_integer(json))
|
||||
if (!json_is_integer(json))
|
||||
return 0;
|
||||
|
||||
return json_to_integer(json)->value;
|
||||
|
@ -845,7 +837,7 @@ json_int_t json_integer_value(const json_t *json)
|
|||
|
||||
int json_integer_set(json_t *json, json_int_t value)
|
||||
{
|
||||
if(!json_is_integer(json))
|
||||
if (!json_is_integer(json))
|
||||
return -1;
|
||||
|
||||
json_to_integer(json)->value = value;
|
||||
|
@ -875,11 +867,11 @@ json_t *json_real(double value)
|
|||
{
|
||||
json_real_t *real;
|
||||
|
||||
if(isnan(value) || isinf(value))
|
||||
if (isnan(value) || isinf(value))
|
||||
return NULL;
|
||||
|
||||
real = jsonp_malloc(sizeof(json_real_t));
|
||||
if(!real)
|
||||
if (!real)
|
||||
return NULL;
|
||||
json_init(&real->json, JSON_REAL);
|
||||
|
||||
|
@ -889,7 +881,7 @@ json_t *json_real(double value)
|
|||
|
||||
double json_real_value(const json_t *json)
|
||||
{
|
||||
if(!json_is_real(json))
|
||||
if (!json_is_real(json))
|
||||
return 0;
|
||||
|
||||
return json_to_real(json)->value;
|
||||
|
@ -897,7 +889,7 @@ double json_real_value(const json_t *json)
|
|||
|
||||
int json_real_set(json_t *json, double value)
|
||||
{
|
||||
if(!json_is_real(json) || isnan(value) || isinf(value))
|
||||
if (!json_is_real(json) || isnan(value) || isinf(value))
|
||||
return -1;
|
||||
|
||||
json_to_real(json)->value = value;
|
||||
|
@ -925,9 +917,9 @@ static json_t *json_real_copy(const json_t *real)
|
|||
|
||||
double json_number_value(const json_t *json)
|
||||
{
|
||||
if(json_is_integer(json))
|
||||
if (json_is_integer(json))
|
||||
return (double)json_integer_value(json);
|
||||
else if(json_is_real(json))
|
||||
else if (json_is_real(json))
|
||||
return json_real_value(json);
|
||||
else
|
||||
return 0.0;
|
||||
|
@ -938,21 +930,21 @@ double json_number_value(const json_t *json)
|
|||
|
||||
json_t *json_true(void)
|
||||
{
|
||||
static json_t the_true = {JSON_TRUE, (size_t)-1};
|
||||
static json_t the_true = {JSON_TRUE, (size_t) -1};
|
||||
return &the_true;
|
||||
}
|
||||
|
||||
|
||||
json_t *json_false(void)
|
||||
{
|
||||
static json_t the_false = {JSON_FALSE, (size_t)-1};
|
||||
static json_t the_false = {JSON_FALSE, (size_t) -1};
|
||||
return &the_false;
|
||||
}
|
||||
|
||||
|
||||
json_t *json_null(void)
|
||||
{
|
||||
static json_t the_null = {JSON_NULL, (size_t)-1};
|
||||
static json_t the_null = {JSON_NULL, (size_t) -1};
|
||||
return &the_null;
|
||||
}
|
||||
|
||||
|
@ -964,7 +956,7 @@ void json_delete(json_t *json)
|
|||
if (!json)
|
||||
return;
|
||||
|
||||
switch(json_typeof(json)) {
|
||||
switch (json_typeof(json)) {
|
||||
case JSON_OBJECT:
|
||||
json_delete_object(json_to_object(json));
|
||||
break;
|
||||
|
@ -992,17 +984,17 @@ void json_delete(json_t *json)
|
|||
|
||||
int json_equal(const json_t *json1, const json_t *json2)
|
||||
{
|
||||
if(!json1 || !json2)
|
||||
if (!json1 || !json2)
|
||||
return 0;
|
||||
|
||||
if(json_typeof(json1) != json_typeof(json2))
|
||||
if (json_typeof(json1) != json_typeof(json2))
|
||||
return 0;
|
||||
|
||||
/* this covers true, false and null as they are singletons */
|
||||
if(json1 == json2)
|
||||
if (json1 == json2)
|
||||
return 1;
|
||||
|
||||
switch(json_typeof(json1)) {
|
||||
switch (json_typeof(json1)) {
|
||||
case JSON_OBJECT:
|
||||
return json_object_equal(json1, json2);
|
||||
case JSON_ARRAY:
|
||||
|
@ -1023,10 +1015,10 @@ int json_equal(const json_t *json1, const json_t *json2)
|
|||
|
||||
json_t *json_copy(json_t *json)
|
||||
{
|
||||
if(!json)
|
||||
if (!json)
|
||||
return NULL;
|
||||
|
||||
switch(json_typeof(json)) {
|
||||
switch (json_typeof(json)) {
|
||||
case JSON_OBJECT:
|
||||
return json_object_copy(json);
|
||||
case JSON_ARRAY:
|
||||
|
@ -1048,16 +1040,16 @@ json_t *json_copy(json_t *json)
|
|||
|
||||
json_t *json_deep_copy(const json_t *json)
|
||||
{
|
||||
if(!json)
|
||||
if (!json)
|
||||
return NULL;
|
||||
|
||||
switch(json_typeof(json)) {
|
||||
switch (json_typeof(json)) {
|
||||
case JSON_OBJECT:
|
||||
return json_object_deep_copy(json);
|
||||
case JSON_ARRAY:
|
||||
return json_array_deep_copy(json);
|
||||
/* for the rest of the types, deep copying doesn't differ from
|
||||
shallow copying */
|
||||
/* for the rest of the types, deep copying doesn't differ from
|
||||
shallow copying */
|
||||
case JSON_STRING:
|
||||
return json_string_copy(json);
|
||||
case JSON_INTEGER:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue