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.

Arguments

Type IntentOptional AttributesName
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.


Contents

Source Code


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