getpath/1 should be a path expression (fix #1358)
It needs to be possible to do something like
getpath($paths[]) += 1
meaning: increment all the paths in . that are listed in $paths[].
In order to do this getpath() needs to update the jq->path and
jq->value_at_path as necessary.
This commit is contained in:
1 parent
63791b795a
commit
2fcb257168
3 files changed
+38
-1
No files matched your search
@@ -246,6 +246,28 @@ static void path_append(jq_state* jq, jv component, jv value_at_path) {
|
||||
}
|
||||
}
|
||||
|
||||
/* For f_getpath() */
|
||||
jv
|
||||
_jq_path_append(jq_state *jq, jv v, jv p, jv value_at_path) {
|
||||
if (jq->subexp_nest != 0 ||
|
||||
jv_get_kind(jq->path) != JV_KIND_ARRAY ||
|
||||
!jv_is_valid(value_at_path)) {
|
||||
jv_free(v);
|
||||
jv_free(p);
|
||||
return value_at_path;
|
||||
}
|
||||
if (!jv_identical(v, jv_copy(jq->value_at_path))) {
|
||||
jv_free(p);
|
||||
return value_at_path;
|
||||
}
|
||||
if (jv_get_kind(p) == JV_KIND_ARRAY)
|
||||
jq->path = jv_array_concat(jq->path, p);
|
||||
else
|
||||
jq->path = jv_array_append(jq->path, p);
|
||||
jv_free(jq->value_at_path);
|
||||
return jv_copy(jq->value_at_path = value_at_path);
|
||||
}
|
||||
|
||||
uint16_t* stack_restore(jq_state *jq){
|
||||
while (!stack_pop_will_free(&jq->stk, jq->fork_top)) {
|
||||
if (stack_pop_will_free(&jq->stk, jq->stk_top)) {
|
||||
|
||||
Reference in new issue
Block a user