Tokenize a line from a CSV file. The result is an array of csv_string
types.
Warning
It does not account for delimiters in quotes (these are treated as a new cell). Need to fix!
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(csv_file), | intent(inout) | :: | me | |||
character(len=*), | intent(in) | :: | line | |||
type(csv_string), | intent(out), | dimension(:), allocatable | :: | cells |
subroutine tokenize_csv_line(me,line,cells) implicit none class(csv_file),intent(inout) :: me character(len=*),intent(in) :: line type(csv_string),dimension(:),allocatable,intent(out) :: cells integer :: i !! counter character(len=:),allocatable :: tmp !! a temp string with whitespace removed integer :: n !! length of compressed string call split(line,me%delimiter,me%chunk_size,cells) ! remove quotes if present: do i = 1, size(cells) ! remove whitespace from the string: tmp = trim(adjustl(cells(i)%str)) n = len(tmp) if (n>1) then ! if the first and last non-blank character is ! a quote, then remove them and replace with what ! is inside the quotes. Otherwise, leave it as is. if (tmp(1:1)==me%quote .and. tmp(n:n)==me%quote) then if (n>2) then cells(i)%str = tmp(2:n-1) ! remove the quotes else cells(i)%str = '' ! empty string end if end if end if end do end subroutine tokenize_csv_line