Browse Source

Merge branch 'Protovision-master'

tags/json-c-0.13-20171207
Eric Haszlakiewicz 9 years ago
parent
commit
9edf2418e0
4 changed files with 35 additions and 0 deletions
  1. +15
    -0
      arraylist.c
  2. +2
    -0
      arraylist.h
  3. +5
    -0
      json_object.c
  4. +13
    -0
      json_object.h

+ 15
- 0
arraylist.c View File

@@ -116,3 +116,18 @@ array_list_length(struct array_list *arr)
{
return arr->length;
}

int
array_list_del_idx( struct array_list *arr, int idx, int count )
{
int i, stop;

stop = idx + count;
if ( idx >= arr->length || stop > arr->length ) return -1;
for ( i = idx; i < stop; ++i ) {
if ( arr->array[i] ) arr->free_fn( arr->array[i] );
}
memmove( arr->array + idx, arr->array + stop, (arr->length - stop) * sizeof(void*) );
arr->length -= count;
return 0;
}

+ 2
- 0
arraylist.h View File

@@ -53,6 +53,8 @@ extern void* array_list_bsearch(const void **key,
struct array_list *arr,
int (*sort_fn)(const void *, const void *));

extern int
array_list_del_idx(struct array_list *arr, int i, int count);

#ifdef __cplusplus
}


+ 5
- 0
json_object.c View File

@@ -1078,3 +1078,8 @@ int json_object_equal(struct json_object* jso1, struct json_object* jso2)

return 0;
}

int json_object_array_del_idx(struct json_object *jso, int idx, int count)
{
return array_list_del_idx(jso->o.c_array, idx, count);
}

+ 13
- 0
json_object.h View File

@@ -526,6 +526,19 @@ extern int json_object_array_put_idx(struct json_object *obj, int idx,
extern struct json_object* json_object_array_get_idx(const struct json_object *obj,
int idx);

/** Delete an elements from a specified index in an array (a json_object of type json_type_array)
*
* The reference count will be decremented for each of the deleted objects. If there
* are no more owners of an element that is being deleted, then the value is
* freed. Otherwise, the reference to the value will remain in memory.
*
* @param obj the json_object instance
* @param idx the index to start deleting elements at
* @param count the number of elements to delete
* @returns 0 if the elements were successfully deleted
*/
extern int json_object_array_del_idx(struct json_object *obj, int idx, int count);

/* json_bool type methods */

/** Create a new empty json_object of type json_type_boolean


Loading…
Cancel
Save