split_lines Function

private function split_lines(text) result(lines)

The lines of text, each with its line ending (the last one may have none).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: text

the text

Return Value type(string_t), allocatable, (:)


Called by

proc~~split_lines~~CalledByGraph proc~split_lines split_lines proc~unified_diff unified_diff proc~unified_diff->proc~split_lines proc~process_text process_text proc~process_text->proc~unified_diff proc~process_file process_file proc~process_file->proc~process_text proc~process_stdin process_stdin proc~process_stdin->proc~process_text proc~run run proc~run->proc~process_file proc~run->proc~process_stdin

Source Code

function split_lines(text) result(lines)
    !! The lines of `text`, each with its line ending (the last one may have none).
    character(len=*), intent(in) :: text   !! the text
    type(string_t), allocatable :: lines(:)
    integer :: i, j, n

    n = count([(text(i:i) == achar(10), i=1, len(text))])
    if (len(text) > 0) then
        if (text(len(text):len(text)) /= achar(10)) n = n + 1
    end if
    allocate (lines(n))
    i = 1
    do j = 1, n
        n = index(text(i:), achar(10))
        if (n == 0) then
            lines(j)%s = text(i:)
        else
            lines(j)%s = text(i:i + n - 1)
            i = i + n
        end if
    end do
end function split_lines