fdoc

subroutineelement_endpureprivate

pure subroutine element_end(text, start, tag, stop_at)

The position of the end of the element starting at start, or 0.

Arguments

NameTypeIntentAttributesDescription
textcharacter(len=*)in

the text

startintegerin

where its < is

tagcharacter(len=*)in

its tag, or !-- for a comment

stop_atintegerout

the position of its last >

Calls

Source

Show the code
pure subroutine element_end(text, start, tag, stop_at)
    character(len=*), intent(in) :: text    !! the text
    integer, intent(in) :: start            !! where its `<` is
    character(len=*), intent(in) :: tag     !! its tag, or `!--` for a comment
    integer, intent(out) :: stop_at         !! the position of its last `>`
    character(len=len(text)) :: low
    integer :: i, depth, gt

    stop_at = 0
    if (tag == '!--') then
        i = index(text(start:), '-->')
        if (i > 0) stop_at = start + i + 1
        return
    end if
    if (tag == 'hr') then
        i = index(text(start:), '>')
        if (i > 0) stop_at = start + i - 1
        return
    end if
    low = lowercase(text)
    depth = 0
    i = start
    do while (i <= len(text))
        if (low(i:i) /= '<') then
            i = i + 1
            cycle
        end if
        if (word_at(low, i + 1, tag)) then
            gt = index(low(i:), '>')
            if (gt == 0) return
            if (low(i + gt - 2:i + gt - 2) /= '/') depth = depth + 1
            if (depth == 0) then
                stop_at = i + gt - 1
                return
            end if
            i = i + gt
        else if (word_at(low, i + 2, tag) .and. low(i + 1:i + 1) == '/') then
            depth = depth - 1
            gt = index(low(i:), '>')
            if (gt == 0) return
            if (depth == 0) then
                stop_at = i + gt - 1
                return
            end if
            i = i + gt
        else
            i = i + 1
        end if
    end do
end subroutine element_end

Graphs

Calls

Called by