functionclosing_parenpure
pure integer function closing_paren(s, open)
Position of the ) matching the ( at open in s, skipping strings, or 0.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| s | character(len=*) | in | the text | |
| open | integer | in | position of the |
Result
| Name | Type | Attributes | Description |
|---|---|---|---|
| closing_paren | integer |
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