fdoc

functionclosing_parenpure

pure integer function closing_paren(s, open)

Position of the ) matching the ( at open in s, skipping strings, or 0.

Arguments

NameTypeIntentAttributesDescription
scharacter(len=*)in

the text

openintegerin

position of the (

Result

NameTypeAttributesDescription
closing_pareninteger

Source

Show the code
pure integer function closing_paren(s, open)
    character(len=*), intent(in) :: s   !! the text
    integer, intent(in) :: open         !! position of the `(`
    integer :: k, depth
    character :: quote

    closing_paren = 0
    depth = 0
    quote = ' '
    do k = open, len(s)
        if (quote /= ' ') then
            if (s(k:k) == quote) quote = ' '
            cycle
        end if
        select case (s(k:k))
        case ('"', "'")
            quote = s(k:k)
        case ('(', '[')
            depth = depth + 1
        case (')', ']')
            depth = depth - 1
            if (depth == 0) then
                closing_paren = k
                return
            end if
        end select
    end do
end function closing_paren

Graphs

Called by