trim_comment Subroutine

private subroutine trim_comment(line, comment_chars)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: line
character(len=*), intent(in) :: comment_chars

Called by

proc~~trim_comment~~CalledByGraph proc~trim_comment trim_comment proc~cfg_read_file CFG_read_file proc~cfg_read_file->proc~trim_comment proc~cfg_update_from_arguments CFG_update_from_arguments proc~cfg_update_from_arguments->proc~cfg_read_file

Source Code

  subroutine trim_comment(line, comment_chars)
    character(len=*), intent(inout) :: line
    character(len=*), intent(in)    :: comment_chars
    character                       :: current_char, need_char
    integer                         :: n

    ! Strip comments, but only outside quoted strings (so that var = '#yolo' is
    ! valid when # is a comment char)
    need_char = ""

    do n = 1, len(line)
       current_char = line(n:n)

       if (need_char == "") then
          if (current_char == "'") then
             need_char = "'"    ! Open string
          else if (current_char == '"') then
             need_char = '"'    ! Open string
          else if (index(current_char, comment_chars) /= 0) then
             line = line(1:n-1) ! Trim line up to comment character
             exit
          end if
       else if (current_char == need_char) then
          need_char = ""        ! Close string
       end if

    end do

  end subroutine trim_comment