Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
json-editor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IOPSYS
json-editor
Commits
d503c81a
Commit
d503c81a
authored
Oct 25, 2019
by
Suru Dissanaike
Browse files
Options
Downloads
Patches
Plain Diff
json-editor: WIP json_object_del_by_idx for json-c version 0.12.1
parent
d25fc8c3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/json-editor.c
+34
-4
34 additions, 4 deletions
src/json-editor.c
with
34 additions
and
4 deletions
src/json-editor.c
+
34
−
4
View file @
d503c81a
...
...
@@ -292,13 +292,34 @@ out:
return
0
;
}
struct
json_object
*
json_object_e_del_by_idx
(
struct
json_object
*
arr
,
int
idx
)
{
struct
json_object
*
el
,
*
new
;
int
i
;
if
(
!
json_object_is_type
(
arr
,
json_type_array
))
return
arr
;
new
=
json_object_new_array
();
for
(
i
=
0
;
i
<
json_object_array_length
(
arr
);
i
++
)
{
if
(
i
==
idx
)
continue
;
el
=
json_object_array_get_idx
(
arr
,
i
);
json_object_array_add
(
new
,
el
);
}
return
new
;
}
/**
* del a value key pair to src object
*
*/
static
int
del_val
(
struct
json_object
*
src
,
char
*
key
)
{
struct
json_object
*
val
;
struct
json_object
*
val
,
*
new
,
*
new2
;
int
idx
[
32
];
int
len
,
rv
=
-
1
;
char
parsed_key
[
32
]
=
{
0
};
...
...
@@ -310,6 +331,9 @@ static int del_val(struct json_object *src, char *key)
json_object_object_del
(
src
,
parsed_key
);
rv
=
0
;
}
else
{
if
(
len
>
1
)
new
=
json_object_new_array
();
/* iterate every index that was appended to the key */
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
struct
json_object
*
j_idx
;
...
...
@@ -328,14 +352,20 @@ static int del_val(struct json_object *src, char *key)
/* at final index, delete at specified idx */
else
{
if
(
idx
[
i
]
>
-
1
)
json_object_
array
_del_idx
(
val
,
idx
[
i
]
,
1
);
new2
=
json_object_
e
_del_
by_
idx
(
val
,
idx
[
i
]);
else
json_object_array_del_idx
(
val
,
json_object_array_length
(
val
)
-
1
,
1
);
new2
=
json_object_e_del_by_idx
(
val
,
idx
[
i
]);
if
(
len
>
1
)
json_object_array_add
(
new
,
new2
);
else
new
=
new2
;
rv
=
0
;
}
}
json_object_object_del
(
src
,
parsed_key
);
json_object_object_add
(
src
,
parsed_key
,
new
);
}
out:
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment