strip_comment Function

private pure function strip_comment(line) result(out)

Remove a trailing ! comment, respecting single/double quotes.

Arguments

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

Return Value character(len=:), allocatable


Called by

proc~~strip_comment~~CalledByGraph proc~strip_comment strip_comment proc~collect_tokens collect_tokens proc~collect_tokens->proc~strip_comment proc~next_amp next_amp proc~next_amp->proc~strip_comment proc~read_group_name read_group_name proc~read_group_name->proc~strip_comment proc~skip_to_slash skip_to_slash proc~skip_to_slash->proc~strip_comment proc~dispatch_group dispatch_group proc~dispatch_group->proc~skip_to_slash proc~parse_group_body parse_group_body proc~dispatch_group->proc~parse_group_body proc~parse_from_lines parse_from_lines proc~parse_from_lines->proc~next_amp proc~parse_from_lines->proc~read_group_name proc~parse_from_lines->proc~skip_to_slash proc~parse_from_lines->proc~dispatch_group proc~parse_group_body->proc~collect_tokens proc~parse_file parse_file proc~parse_file->proc~parse_from_lines proc~schema_parse_lines nml_schema_t%schema_parse_lines proc~schema_parse_lines->proc~parse_from_lines proc~read_config_from_string_impl read_config_from_string_impl proc~read_config_from_string_impl->proc~schema_parse_lines proc~schema_parse nml_schema_t%schema_parse proc~schema_parse->proc~parse_file proc~read_config_from_string read_config_from_string proc~read_config_from_string->proc~read_config_from_string_impl proc~read_config_impl read_config_impl proc~read_config_impl->proc~schema_parse

Variables

Type Visibility Attributes Name Initial
integer, private :: i
logical, private :: in_str
character(len=1), private :: q

Source Code

   pure function strip_comment(line) result(out)
      !! Remove a trailing `!` comment, respecting single/double quotes.
      character(len=*), intent(in) :: line
      character(len=:), allocatable :: out
      integer :: i
      character :: q
      logical :: in_str

      in_str = .false.
      q = " "
      out = line
      do i = 1, len(line)
         if (in_str) then
            if (line(i:i) == q) in_str = .false.
         else
            if (line(i:i) == '"' .or. line(i:i) == "'") then
               in_str = .true.
               q = line(i:i)
            else if (line(i:i) == "!") then
               out = line(1:i - 1)
               return
            end if
         end if
      end do
   end function strip_comment