fdoc

subroutinewithout_carriage_returnspureprivate

pure subroutine without_carriage_returns(text)

Turn the line ends of text into a line feed, as Python does when it reads text.

Arguments

NameTypeIntentAttributesDescription
textcharacter(len=:)inoutallocatable

the text

Source

Show the code
pure subroutine without_carriage_returns(text)
    character(len=:), allocatable, intent(inout) :: text    !! the text
    integer :: from, to

    if (index(text, achar(13)) == 0) return
    to = 0
    do from = 1, len(text)
        if (text(from:from) == achar(13)) then
            if (from == len(text)) then
                to = to + 1
                text(to:to) = NL
                cycle
            end if
            if (text(from + 1:from + 1) == NL) cycle
            to = to + 1
            text(to:to) = NL
            cycle
        end if
        to = to + 1
        text(to:to) = text(from:from)
    end do
    text = text(:to)
end subroutine without_carriage_returns

Graphs

Called by