string_to_int Function

private function string_to_int(json, str) result(ival)

Convert a string into an integer.


Type IntentOptional AttributesName
class(json_core), intent(inout) :: json
character(kind=CK,len=*), intent(in) :: str

a string

Return Value integer(kind=IK)

str converted to an integer


proc~~string_to_int~~CallsGraph proc~string_to_int string_to_int proc~string_to_integer string_to_integer proc~string_to_int->proc~string_to_integer


Source Code

Source Code

    function string_to_int(json,str) result(ival)

    implicit none

    class(json_core),intent(inout)      :: json
    character(kind=CK,len=*),intent(in) :: str   !! a string
    integer(IK)                         :: ival  !! `str` converted to an integer

    logical(LK) :: status_ok !! error flag for [[string_to_integer]]

    if (.not. json%exception_thrown) then

        ! call the core routine:
        call string_to_integer(str,ival,status_ok)

        if (.not. status_ok) then
            ival = 0
            call json%throw_exception('Error in string_to_int: '//&
                                      'string cannot be converted to an integer: '//&
        end if

        ival = 0
    end if

    end function string_to_int