json_value_replace Subroutine

private subroutine json_value_replace(json, p1, p2, destroy)

Replace p1 with p2 in a JSON structure.

Arguments

TypeIntentOptionalAttributesName
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(kind=LK), intent(in), optional :: destroy

Should p1 also be destroyed (default is True). Normally, this should be true to avoid a memory leak.


Contents

Source Code


Source Code

    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