update_array_bracket_depth Subroutine

subroutine update_array_bracket_depth(line, depth)

Update square-bracket nesting depth for multiline JSON arrays.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: line

Current JSON line inside a multiline array

integer, intent(inout) :: depth

Mutable array nesting depth


Source Code

  subroutine update_array_bracket_depth(line, depth)
    !! Update square-bracket nesting depth for multiline JSON arrays.
    implicit none

    ! Arguments
    character(*), intent(in) :: line
    !! Current JSON line inside a multiline array
    integer, intent(inout) :: depth
    !! Mutable array nesting depth

    ! Local variables
    integer :: i
    !! Character index while scanning brackets

    do i = 1, len_trim(line)
       if(line(i:i) .eq. '[') depth = depth + 1
       if(line(i:i) .eq. ']') depth = depth - 1
    end do

  end subroutine update_array_bracket_depth