assign_json_file_to_string Subroutine

private subroutine assign_json_file_to_string(str, me)

Assignment operator for character = json_core. This is just a wrapper for the json_value_to_string routine.

Note

  • If an exception is raised or the file contains no data, this will return an empty string.

Arguments

Type IntentOptional AttributesName
character(kind=CK,len=:), intent(out), allocatable:: str
class(json_file), intent(in) :: me

Contents


Source Code

    subroutine assign_json_file_to_string(str,me)

    implicit none

    character(kind=CK,len=:),allocatable,intent(out) :: str
    class(json_file),intent(in) :: me

    type(json_core) :: core_copy !! a copy of `core` from `me`

    if (me%core%failed() .or. .not. associated(me%p)) then
        str = CK_''
    else

        ! This is sort of a hack. Since `me` has to have `intent(in)`
        ! for the assignment to work, we need to make a copy of `me%core`
        ! so we can call the low level routine (since it needs it to
        ! be `intent(inout)`) because it's possible for this
        ! function to raise an exception.

        core_copy = me%core ! copy the parser settings

        call core_copy%serialize(me%p,str)
        if (me%core%failed()) str = CK_''

    end if

    end subroutine assign_json_file_to_string