read_lines_expanded Function

public function read_lines_expanded(filename) result(lines)

read lines into an array of TYPE(STRING_T) variables expanding tabs

Arguments

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

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


Source Code

function read_lines_expanded(filename) result(lines)
    character(len=*), intent(in) :: filename
    type(string_t), allocatable :: lines(:)

    integer :: i
    character(len=:), allocatable :: content
    integer, allocatable :: first(:), last(:)

    content = read_text_file(filename)
    if (len(content) == 0) then
        allocate (lines(0))
        return
    end if

    call split_first_last(content, eol, first, last)  ! TODO: \r (< macOS X), \n (>=macOS X/Linux/Unix), \r\n (Windows)

    ! allocate lines from file content string
    allocate (lines(size(first)))
    do i = 1, size(first)
        allocate(lines(i)%s, source=dilate(content(first(i):last(i))))
    end do

end function read_lines_expanded