Change the json_value variable to a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK,len=*), | intent(in), | optional | :: | val | if the value is also to be set (if not present, then '' is used). |
|
character(kind=CK,len=*), | intent(in), | optional | :: | name | if the name is also to be changed. |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str | if TRIM() should be called for the |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str | if ADJUSTL() should be called for the |
subroutine to_string(json,p,val,name,trim_str,adjustl_str)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer :: p
character(kind=CK,len=*),intent(in),optional :: val !! if the value is also to be set
!! (if not present, then '' is used).
character(kind=CK,len=*),intent(in),optional :: name !! if the name is also to be changed.
logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val`
!! (only used if `val` is present)
logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val`
!! (only used if `val` is present)
!! (note that ADJUSTL is done before TRIM)
character(kind=CK,len=:),allocatable :: str !! temp string for `trim()` and/or `adjustl()`
logical :: trim_string !! if the string is to be trimmed
logical :: adjustl_string !! if the string is to be adjusted left
!set type and value:
call destroy_json_data(p)
p%var_type = json_string
if (present(val)) then
if (present(trim_str)) then
trim_string = trim_str
else
trim_string = .false.
end if
if (present(adjustl_str)) then
adjustl_string = adjustl_str
else
adjustl_string = .false.
end if
if (trim_string .or. adjustl_string) then
str = val
if (adjustl_string) str = adjustl(str)
if (trim_string) str = trim(str)
p%str_value = str
else
p%str_value = val
end if
else
p%str_value = CK_'' ! default value
end if
!name:
if (present(name)) call json%rename(p,name)
end subroutine to_string