Permalink
Browse files

Minor interface change to match libape_spidermonkey changes

  • Loading branch information...
1 parent 8f8166c commit 9e85a696bbfe3a76379337af8ad31053d121c3de @paraboul paraboul committed Jun 25, 2011
Showing with 71 additions and 26 deletions.
  1. +64 −19 src/json.c
  2. +7 −7 src/json.h
View
@@ -458,13 +458,17 @@ json_item *json_new_array()
return obj;
}
-void json_set_property_objN(json_item *obj, const char *key, int keylen, json_item *value)
+json_item *json_set_property_objN(json_item *obj, const char *key, int keylen, json_item *value)
{
json_item *new_item = value;
if (key != NULL) {
new_item->key.val = xmalloc(sizeof(char) * (keylen + 1));
- memcpy(new_item->key.val, key, keylen + 1);
+ if (*key != '\0') {
+ memcpy(new_item->key.val, key, keylen + 1);
+ } else {
+ memset(new_item->key.val, '\0', sizeof(char) * (keylen + 1));
+ }
new_item->key.len = keylen;
}
@@ -477,20 +481,26 @@ void json_set_property_objN(json_item *obj, const char *key, int keylen, json_it
}
obj->jchild.head = new_item;
+
+ return new_item;
}
void json_set_property_objZ(json_item *obj, const char *key, json_item *value)
{
json_set_property_objN(obj, key, strlen(key), value);
}
-void json_set_property_intN(json_item *obj, const char *key, int keylen, JSON_int_t value)
+json_item *json_set_property_intN(json_item *obj, const char *key, int keylen, JSON_int_t value)
{
json_item *new_item = init_json_item();
if (key != NULL) {
new_item->key.val = xmalloc(sizeof(char) * (keylen + 1));
- memcpy(new_item->key.val, key, keylen + 1);
+ if (*key != '\0') {
+ memcpy(new_item->key.val, key, keylen + 1);
+ } else {
+ memset(new_item->key.val, '\0', keylen + 1);
+ }
new_item->key.len = keylen;
}
new_item->father = obj;
@@ -503,7 +513,9 @@ void json_set_property_intN(json_item *obj, const char *key, int keylen, JSON_in
obj->jchild.head->next = new_item;
}
- obj->jchild.head = new_item;
+ obj->jchild.head = new_item;
+
+ return new_item;
}
void json_set_property_intZ(json_item *obj, const char *key, JSON_int_t value)
@@ -513,13 +525,18 @@ void json_set_property_intZ(json_item *obj, const char *key, JSON_int_t value)
json_set_property_intN(obj, key, len, value);
}
-void json_set_property_floatN(json_item *obj, const char *key, int keylen, long double value)
+json_item *json_set_property_floatN(json_item *obj, const char *key, int keylen, long double value)
{
json_item *new_item = init_json_item();
if (key != NULL) {
new_item->key.val = xmalloc(sizeof(char) * (keylen + 1));
- memcpy(new_item->key.val, key, keylen + 1);
+
+ if (*key != '\0') {
+ memcpy(new_item->key.val, key, keylen + 1);
+ } else {
+ memset(new_item->key.val, '\0', keylen + 1);
+ }
new_item->key.len = keylen;
}
new_item->father = obj;
@@ -532,16 +549,23 @@ void json_set_property_floatN(json_item *obj, const char *key, int keylen, long
obj->jchild.head->next = new_item;
}
- obj->jchild.head = new_item;
+ obj->jchild.head = new_item;
+
+ return new_item;
}
-void json_set_property_boolean(json_item *obj, const char *key, int keylen, int value)
+json_item *json_set_property_boolean(json_item *obj, const char *key, int keylen, int value)
{
json_item *new_item = init_json_item();
if (key != NULL) {
new_item->key.val = xmalloc(sizeof(char) * (keylen + 1));
- memcpy(new_item->key.val, key, keylen + 1);
+
+ if (*key != '\0') {
+ memcpy(new_item->key.val, key, keylen + 1);
+ } else {
+ memset(new_item->key.val, '\0', keylen + 1);
+ }
new_item->key.len = keylen;
}
new_item->father = obj;
@@ -556,16 +580,23 @@ void json_set_property_boolean(json_item *obj, const char *key, int keylen, int
obj->jchild.head->next = new_item;
}
- obj->jchild.head = new_item;
+ obj->jchild.head = new_item;
+
+ return new_item;
}
-void json_set_property_null(json_item *obj, const char *key, int keylen)
+json_item *json_set_property_null(json_item *obj, const char *key, int keylen)
{
json_item *new_item = init_json_item();
if (key != NULL) {
new_item->key.val = xmalloc(sizeof(char) * (keylen + 1));
- memcpy(new_item->key.val, key, keylen + 1);
+
+ if (*key != '\0') {
+ memcpy(new_item->key.val, key, keylen + 1);
+ } else {
+ memset(new_item->key.val, '\0', sizeof(char) * (keylen + 1));
+ }
new_item->key.len = keylen;
}
new_item->father = obj;
@@ -577,22 +608,34 @@ void json_set_property_null(json_item *obj, const char *key, int keylen)
obj->jchild.head->next = new_item;
}
- obj->jchild.head = new_item;
+ obj->jchild.head = new_item;
+
+ return new_item;
}
-void json_set_property_strN(json_item *obj, const char *key, int keylen, const char *value, int valuelen)
+json_item *json_set_property_strN(json_item *obj, const char *key, int keylen, const char *value, int valuelen)
{
json_item *new_item = init_json_item();
if (key != NULL) {
new_item->key.val = xmalloc(sizeof(char) * (keylen + 1));
- memcpy(new_item->key.val, key, keylen + 1);
+
+ if (*key != '\0') {
+ memcpy(new_item->key.val, key, keylen + 1);
+ } else {
+ memset(new_item->key.val, '\0', sizeof(char) * (keylen + 1));
+ }
new_item->key.len = keylen;
}
+
new_item->jval.vu.str.value = xmalloc(sizeof(char) * (valuelen + 1));
- memcpy(new_item->jval.vu.str.value, value, valuelen + 1);
+ if (*value != '\0') {
+ memcpy(new_item->jval.vu.str.value, value, valuelen + 1);
+ } else {
+ memset(new_item->jval.vu.str.value, '\0', valuelen + 1);
+ }
new_item->jval.vu.str.length = valuelen;
new_item->type = JSON_T_STRING;
@@ -605,6 +648,8 @@ void json_set_property_strN(json_item *obj, const char *key, int keylen, const c
}
obj->jchild.head = new_item;
+
+ return new_item;
}
void json_set_property_strZ(json_item *obj, const char *key, const char *value)
@@ -614,9 +659,9 @@ void json_set_property_strZ(json_item *obj, const char *key, const char *value)
json_set_property_strN(obj, key, len, value, strlen(value));
}
-void json_set_element_strN(json_item *obj, const char *value, int valuelen)
+json_item *json_set_element_strN(json_item *obj, const char *value, int valuelen)
{
- json_set_property_strN(obj, NULL, 0, value, valuelen);
+ return json_set_property_strN(obj, NULL, 0, value, valuelen);
}
void json_set_element_strZ(json_item *obj, const char *value)
View
@@ -114,25 +114,25 @@ void free_json_item(json_item *cx);
json_item *json_new_object();
json_item *json_new_array();
-void json_set_property_objN(json_item *obj, const char *key, int keylen, json_item *value);
+json_item *json_set_property_objN(json_item *obj, const char *key, int keylen, json_item *value);
void json_set_property_objZ(json_item *obj, const char *key, json_item *value);
-void json_set_property_strN(json_item *obj, const char *key, int keylen, const char *value, int valuelen);
+json_item *json_set_property_strN(json_item *obj, const char *key, int keylen, const char *value, int valuelen);
void json_set_property_strZ(json_item *obj, const char *key, const char *value);
-void json_set_element_strN(json_item *obj, const char *value, int valuelen);
+json_item *json_set_element_strN(json_item *obj, const char *value, int valuelen);
void json_set_element_strZ(json_item *obj, const char *value);
void json_set_element_int(json_item *obj, long int value);
void json_set_element_float(json_item *obj, long double value);
void json_set_element_boolean(json_item *obj, int value);
void json_set_element_null(json_item *obj);
void json_set_element_obj(json_item *obj, json_item *value);
-void json_set_property_intN(json_item *obj, const char *key, int keylen, JSON_int_t value);
+json_item *json_set_property_intN(json_item *obj, const char *key, int keylen, JSON_int_t value);
void json_set_property_intZ(json_item *obj, const char *key, JSON_int_t value);
-void json_set_property_floatN(json_item *obj, const char *key, int keylen, long double value);
-void json_set_property_boolean(json_item *obj, const char *key, int keylen, int value);
-void json_set_property_null(json_item *obj, const char *key, int keylen);
+json_item *json_set_property_floatN(json_item *obj, const char *key, int keylen, long double value);
+json_item *json_set_property_boolean(json_item *obj, const char *key, int keylen, int value);
+json_item *json_set_property_null(json_item *obj, const char *key, int keylen);
struct jsontring *json_to_string(json_item *head, struct jsontring *string, int free_tree);
json_item *json_item_copy(json_item *cx, json_item *father);

0 comments on commit 9e85a69

Please sign in to comment.