string_to_int Function

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

Convert a string into an integer.

Note

Replacement for the parse_integer function in the original code.

Type Bound

json_core

Arguments

Type IntentOptional Attributes Name
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


Calls

proc~~string_to_int~~CallsGraph proc~string_to_int json_core%string_to_int none~throw_exception json_core%throw_exception proc~string_to_int->none~throw_exception proc~string_to_integer string_to_integer proc~string_to_int->proc~string_to_integer proc~json_throw_exception json_core%json_throw_exception none~throw_exception->proc~json_throw_exception proc~wrap_json_throw_exception json_core%wrap_json_throw_exception none~throw_exception->proc~wrap_json_throw_exception proc~wrap_json_throw_exception->none~throw_exception interface~to_unicode to_unicode proc~wrap_json_throw_exception->interface~to_unicode proc~to_uni to_uni interface~to_unicode->proc~to_uni proc~to_uni_vec to_uni_vec interface~to_unicode->proc~to_uni_vec

Called by

proc~~string_to_int~~CalledByGraph proc~string_to_int json_core%string_to_int proc~parse_number json_core%parse_number proc~parse_number->proc~string_to_int proc~parse_value json_core%parse_value proc~parse_value->proc~parse_number proc~parse_array json_core%parse_array proc~parse_value->proc~parse_array proc~parse_object json_core%parse_object proc~parse_value->proc~parse_object proc~json_parse_file json_core%json_parse_file proc~json_parse_file->proc~parse_value proc~json_parse_string json_core%json_parse_string proc~json_parse_string->proc~parse_value proc~parse_array->proc~parse_value proc~parse_object->proc~parse_value proc~parse_object->proc~parse_object none~deserialize~2 json_core%deserialize none~deserialize~2->proc~json_parse_string proc~wrap_json_parse_string json_core%wrap_json_parse_string none~deserialize~2->proc~wrap_json_parse_string none~load~2 json_core%load none~load~2->proc~json_parse_file proc~json_file_load json_file%json_file_load proc~json_file_load->none~load~2 proc~json_file_load_from_string json_file%json_file_load_from_string proc~json_file_load_from_string->none~deserialize~2 proc~wrap_json_parse_string->none~deserialize~2 none~deserialize json_file%deserialize none~deserialize->proc~json_file_load_from_string proc~wrap_json_file_load_from_string json_file%wrap_json_file_load_from_string none~deserialize->proc~wrap_json_file_load_from_string proc~assign_string_to_json_file json_file%assign_string_to_json_file proc~assign_string_to_json_file->none~deserialize proc~initialize_json_file_from_string initialize_json_file_from_string proc~initialize_json_file_from_string->none~deserialize proc~initialize_json_file_from_string_v2 initialize_json_file_from_string_v2 proc~initialize_json_file_from_string_v2->none~deserialize proc~wrap_json_file_load_from_string->none~deserialize interface~json_file json_file interface~json_file->proc~initialize_json_file_from_string interface~json_file->proc~initialize_json_file_from_string_v2 proc~wrap_initialize_json_file_from_string wrap_initialize_json_file_from_string interface~json_file->proc~wrap_initialize_json_file_from_string proc~wrap_initialize_json_file_from_string_v2 wrap_initialize_json_file_from_string_v2 interface~json_file->proc~wrap_initialize_json_file_from_string_v2 proc~wrap_assign_string_to_json_file json_file%wrap_assign_string_to_json_file proc~wrap_assign_string_to_json_file->proc~assign_string_to_json_file proc~wrap_initialize_json_file_from_string->proc~initialize_json_file_from_string proc~wrap_initialize_json_file_from_string_v2->proc~initialize_json_file_from_string_v2

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]]

    ! 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: '//&
                                    trim(str))
    end if

    end function string_to_int