Replace p1
with p2
in a JSON structure.
The replacement is done using an insert and remove See json_value_insert_after and json_value_remove for details.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p1 | the item to replace |
||
type(json_value), | pointer | :: | p2 | item to take the place of |
||
logical(kind=LK), | intent(in), | optional | :: | destroy | Should |
subroutine json_value_replace(json,p1,p2,destroy)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer :: p1 !! the item to replace
type(json_value),pointer :: p2 !! item to take the place of `p1`
logical(LK),intent(in),optional :: destroy !! Should `p1` also be destroyed
!! (default is True). Normally,
!! this should be true to avoid
!! a memory leak.
logical(LK) :: destroy_p1 !! if `p1` is to be destroyed
if (present(destroy)) then
destroy_p1 = destroy
else
destroy_p1 = .true. ! default
end if
call json%insert_after(p1,p2)
call json%remove(p1,destroy_p1)
end subroutine json_value_replace