fdoc

subroutinesubstitute_aliasesprivate

subroutine substitute_aliases(lines, aliases)

Replace |alias| by its value. |alias| gives the text without the backslash.

Arguments

NameTypeIntentAttributesDescription
linestype(string_t)inoutdimension(:)

the lines

aliasestype(map_entry_t)indimension(:)

the aliases

Calls

Source

Show the code
subroutine substitute_aliases(lines, aliases)
    type(string_t), intent(inout) :: lines(:)       !! the lines
    type(map_entry_t), intent(in) :: aliases(:)     !! the aliases
    type(buffer_t) :: b
    integer :: k, i, j, a
    logical :: found, changed

    do k = 1, size(lines)
        if (index(lines(k)%s, '|') == 0) cycle
        associate (line => lines(k)%s)
            changed = .false.
            i = 1
            do while (i <= len(line))
                if (line(i:i) /= '|') then
                    call add(b, line(i:i))
                    i = i + 1
                    cycle
                end if
                j = 0
                if (i < len(line)) then
                    if (line(i + 1:i + 1) /= ' ') j = index(line(i + 1:), '|')
                end if
                found = .false.
                if (j > 0 .and. (i == 1 .or. line(max(1, i - 1):max(1, i - 1)) /= '\')) then
                    do a = 1, size(aliases)
                        if (aliases(a)%key == line(i + 1:i + j - 1)) then
                            call add(b, aliases(a)%value)
                            i = i + j + 1
                            found = .true.
                            changed = .true.
                            exit
                        end if
                    end do
                end if
                if (found) cycle
                if (i > 1 .and. j > 0) then
                    if (line(i - 1:i - 1) == '\' .and. b%n > 0) then
                        b%n = b%n - 1
                        changed = .true.
                    end if
                end if
                call add(b, '|')
                i = i + 1
            end do
        end associate
        if (changed) then
            call take(b, lines(k)%s)
        else
            b%n = 0
        end if
    end do
end subroutine substitute_aliases

Graphs

Calls

Called by