aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-05 13:08:51 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-01-05 13:08:51 +0200
commit384b8c088c290f06f70835402f903627c67de6f3 (patch)
tree3a0659fed44bdb9f11f621e975ed02dff37f9731
parent3b73967c62da68d865f32ca91c8407e65b8ddc03 (diff)
downloadgrecs-384b8c088c290f06f70835402f903627c67de6f3.tar.gz
grecs-384b8c088c290f06f70835402f903627c67de6f3.tar.bz2
Implement json_array_set
-rw-r--r--src/json-gram.y18
-rw-r--r--src/json.h1
2 files changed, 18 insertions, 1 deletions
diff --git a/src/json-gram.y b/src/json-gram.y
index ecfb561..ab65362 100644
--- a/src/json-gram.y
+++ b/src/json-gram.y
@@ -487,3 +487,3 @@ json_array_append(struct json_value *j, struct json_value *v)
{
- if (j->type != json_arr) {
+ if (j->type != json_arr) {
errno = EINVAL;
@@ -499,2 +499,18 @@ json_array_append(struct json_value *j, struct json_value *v)
int
+json_array_set(struct json_value *j, size_t idx, struct json_value *v)
+{
+ if (j->type != json_arr) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (idx >= json_array_size(j)) {
+ errno = ENOENT;
+ return -1;
+ }
+ json_array_flatten(j);
+ j->v.a->ov[idx] = v;
+ return 0;
+}
+
+int
json_array_get(struct json_value *j, size_t idx, struct json_value **retval)
diff --git a/src/json.h b/src/json.h
index 7dffc4b..bd2c3d9 100644
--- a/src/json.h
+++ b/src/json.h
@@ -95,2 +95,3 @@ int json_array_insert(struct json_value *j, size_t idx, struct json_value *v);
int json_array_append(struct json_value *j, struct json_value *v);
+int json_array_set(struct json_value *j, size_t idx, struct json_value *v);
int json_array_get(struct json_value *j, size_t idx,

Return to:

Send suggestions and report system problems to the System administrator.