parse_for_chars Subroutine

private subroutine parse_for_chars(json, unit, str, chars)

Core parsing routine.

This is used to verify the strings true, false, and null during parsing.

Type Bound

json_core

Arguments

Type IntentOptional Attributes Name
class(json_core), intent(inout) :: json
integer(kind=IK), intent(in) :: unit

file unit number (if parsing from a file)

character(kind=CK, len=*), intent(in) :: str

JSON string (if parsing from a string)

character(kind=CK, len=*), intent(in) :: chars

the string to check for.


Calls

proc~~parse_for_chars~~CallsGraph proc~parse_for_chars json_core%parse_for_chars none~throw_exception json_core%throw_exception proc~parse_for_chars->none~throw_exception proc~pop_char json_core%pop_char proc~parse_for_chars->proc~pop_char proc~json_throw_exception json_core%json_throw_exception none~throw_exception->proc~json_throw_exception

Called by

proc~~parse_for_chars~~CalledByGraph proc~parse_for_chars json_core%parse_for_chars proc~parse_value json_core%parse_value proc~parse_value->proc~parse_for_chars 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 json_core%deserialize none~deserialize->proc~json_parse_string none~load json_core%load none~load->proc~json_parse_file proc~json_file_load json_file%json_file_load proc~json_file_load->none~load proc~json_file_load_from_string json_file%json_file_load_from_string proc~json_file_load_from_string->none~deserialize proc~wrap_json_parse_string wrap_json_parse_string proc~wrap_json_parse_string->none~deserialize none~deserialize~2 json_file%deserialize none~deserialize~2->proc~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~2 proc~initialize_json_file_from_string initialize_json_file_from_string proc~initialize_json_file_from_string->none~deserialize~2 proc~initialize_json_file_from_string_v2 initialize_json_file_from_string_v2 proc~initialize_json_file_from_string_v2->none~deserialize~2 proc~wrap_json_file_load_from_string wrap_json_file_load_from_string proc~wrap_json_file_load_from_string->none~deserialize~2 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_assign_string_to_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 wrap_initialize_json_file_from_string proc~wrap_initialize_json_file_from_string->proc~initialize_json_file_from_string proc~wrap_initialize_json_file_from_string_v2 wrap_initialize_json_file_from_string_v2 proc~wrap_initialize_json_file_from_string_v2->proc~initialize_json_file_from_string_v2

Source Code

    subroutine parse_for_chars(json, unit, str, chars)

    implicit none

    class(json_core),intent(inout)      :: json
    integer(IK),intent(in)              :: unit   !! file unit number (if parsing from a file)
    character(kind=CK,len=*),intent(in) :: str    !! JSON string (if parsing from a string)
    character(kind=CK,len=*),intent(in) :: chars  !! the string to check for.

    integer(IK) :: i               !! counter
    integer(IK) :: length          !! trimmed length of `chars`
    logical(LK) :: eof             !! end of file flag
    character(kind=CK,len=1) :: c  !! character returned by [[pop_char]]

    if (.not. json%exception_thrown) then

        length = len_trim(chars)

        do i = 1, length
            call json%pop_char(unit, str=str, eof=eof, skip_ws=.false., popped=c)
            if (eof) then
                call json%throw_exception('Error in parse_for_chars:'//&
                                     ' Unexpected end of file while parsing.')
                return
            else if (c /= chars(i:i)) then
                call json%throw_exception('Error in parse_for_chars:'//&
                                     ' Unexpected character: "'//c//'" (expecting "'//&
                                     chars(i:i)//'")')
                return
            end if
        end do

    end if

    end subroutine parse_for_chars