]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Merge branch 'master' of https://github.com/Protovision/json-c into Protovision-master
authorEric Haszlakiewicz <erh+git@nimenees.com>
Sat, 30 Apr 2016 18:52:47 +0000 (18:52 +0000)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Sat, 30 Apr 2016 18:52:47 +0000 (18:52 +0000)
1  2 
arraylist.c
json_object.c
json_object.h

diff --cc arraylist.c
Simple merge
diff --cc json_object.c
index b5083f34a556d22c67f6ebaf87ff8cf3646e726c,d09518f1a1fe2b1443399a39db37a7660c714ca6..7d6088488cb3af4ad30fdebd51fc5e3d75091043
@@@ -997,84 -926,7 +997,89 @@@ struct json_object* json_object_array_g
        return (struct json_object*)array_list_get_idx(jso->o.c_array, idx);
  }
  
 +static int json_array_equal(struct json_object* jso1,
 +                          struct json_object* jso2)
 +{
 +      int len, i;
 +
 +      len = json_object_array_length(jso1);
 +      if (len != json_object_array_length(jso2))
 +              return 0;
 +
 +      for (i = 0; i < len; i++) {
 +              if (!json_object_equal(json_object_array_get_idx(jso1, i),
 +                                     json_object_array_get_idx(jso2, i)))
 +                      return 0;
 +      }
 +      return 1;
 +}
 +
 +static int json_object_all_values_equal(struct json_object* jso1,
 +                                      struct json_object* jso2)
 +{
 +      struct json_object_iter iter;
 +      struct json_object *sub;
 +
 +      /* Iterate over jso1 keys and see if they exist and are equal in jso2 */
 +        json_object_object_foreachC(jso1, iter) {
 +              if (!lh_table_lookup_ex(jso1->o.c_object, (void*)iter.key,
 +                                      (void**)&sub))
 +                      return 0;
 +              if (!json_object_equal(iter.val, sub))
 +                      return 0;
 +        }
 +
 +      /* Iterate over jso2 keys to see if any exist that are not in jso1 */
 +        json_object_object_foreachC(jso2, iter) {
 +              if (!lh_table_lookup_ex(jso1->o.c_object, (void*)iter.key,
 +                                      (void**)&sub))
 +                      return 0;
 +        }
 +
 +      return 1;
 +}
 +
 +int json_object_equal(struct json_object* jso1, struct json_object* jso2)
 +{
 +      if (jso1 == jso2)
 +              return 1;
 +
 +      if (!jso1 || !jso2)
 +              return 0;
 +
 +      if (jso1->o_type != jso2->o_type)
 +              return 0;
 +
 +      switch(jso1->o_type) {
 +              case json_type_boolean:
 +                      return (jso1->o.c_boolean == jso2->o.c_boolean);
 +
 +              case json_type_double:
 +                      return (jso1->o.c_double == jso2->o.c_double);
 +
 +              case json_type_int:
 +                      return (jso1->o.c_int64 == jso2->o.c_int64);
 +
 +              case json_type_string:
 +                      return (jso1->o.c_string.len == jso2->o.c_string.len &&
 +                              memcmp(get_string_component(jso1),
 +                                     get_string_component(jso2),
 +                                     jso1->o.c_string.len) == 0);
 +
 +              case json_type_object:
 +                      return json_object_all_values_equal(jso1, jso2);
 +
 +              case json_type_array:
 +                      return json_array_equal(jso1, jso2);
 +
 +              case json_type_null:
 +                      return 1;
 +      };
 +
 +      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);
+ }
diff --cc json_object.h
index f4d9e79d86d7653db5b932dcc19375a131b4e51c,ad6af8e7439629fcd3c726965576d722ec2b5999..2d1ba94be45de9c2d50c8d0b1f64cdee1a08acf6
@@@ -523,9 -461,22 +523,22 @@@ extern int json_object_array_put_idx(st
   * @param idx the index to get the element at
   * @returns the json_object at the specified index (or NULL)
   */
 -extern struct json_object* json_object_array_get_idx(struct json_object *obj,
 +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