summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/array.c8
-rw-r--r--src/object.c12
2 files changed, 16 insertions, 4 deletions
diff --git a/src/array.c b/src/array.c
index edf7ed9..c34a8e5 100644
--- a/src/array.c
+++ b/src/array.c
@@ -66,13 +66,17 @@ bool json_array_append(struct json *dest, struct json *src) {
return true;
}
-struct json *json_array_get(const struct json *json, size_t index) {
- if (index > json->children->nitems)
+struct json *json_array_get_mut(struct json *json, size_t index) {
+ if (json->type != JSON_ARRAY || index > json->children->nitems)
return NULL;
return json->children->items[index];
}
+const struct json *json_array_get_const(const struct json *array, size_t index) {
+ return json_array_get_mut((struct json *) array, index);
+}
+
struct json *json_array_add_object(struct json *dest) {
struct json *obj = json_new_object();
json_array_append(dest, obj);
diff --git a/src/object.c b/src/object.c
index 7178bdd..fea4787 100644
--- a/src/object.c
+++ b/src/object.c
@@ -133,7 +133,7 @@ bool json_object_add(struct json *dest, const char *key, struct json *src) {
return true;
}
-struct json *json_object_get(const struct json *obj, const char *key) {
+struct json *json_object_get_mut(struct json *obj, const char *key) {
if (obj->type != JSON_OBJECT) return NULL;
struct json *j = NULL;
json_foreach(j, obj) {
@@ -143,7 +143,7 @@ struct json *json_object_get(const struct json *obj, const char *key) {
return j;
}
-struct json *json_object_getn(const struct json *obj, const char *key, size_t n) {
+struct json *json_object_getn_mut(struct json *obj, const char *key, size_t n) {
if (obj->type != JSON_OBJECT) return NULL;
struct json *j = NULL;
json_foreach(j, obj) {
@@ -153,6 +153,14 @@ struct json *json_object_getn(const struct json *obj, const char *key, size_t n)
return j;
}
+const struct json *json_object_get_const(const struct json *obj, const char *key) {
+ return json_object_get_mut((struct json *) obj, key);
+}
+
+const struct json *json_object_getn_const(const struct json *obj, const char *key, size_t n) {
+ return json_object_getn_mut((struct json *) obj, key, n);
+}
+
struct json *json_object_add_object(struct json *dest, const char *key) {
struct json *obj = json_new_object();
json_object_add(dest, key, obj);