quote_arg Function

public function quote_arg(a) result(q)

Quote an argument for the host shell, escaping embedded quotes as needed.

  • On Windows, " is doubled.
  • On POSIX shells, ' is escaped using a standard ''"'"' pattern.

Arguments

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

Return Value character(len=:), allocatable


Calls

proc~~quote_arg~~CallsGraph proc~quote_arg quote_arg proc~is_windows_os is_windows_os proc~quote_arg->proc~is_windows_os get_os_type get_os_type proc~is_windows_os->get_os_type

Called by

proc~~quote_arg~~CalledByGraph proc~quote_arg quote_arg proc~build_child_command build_child_command proc~build_child_command->proc~quote_arg proc~join_argv join_argv proc~join_argv->proc~quote_arg proc~parse_cli parse_cli proc~parse_cli->proc~join_argv proc~supervisor_loop supervisor_loop proc~supervisor_loop->proc~build_child_command proc~maybe_supervise maybe_supervise proc~maybe_supervise->proc~supervisor_loop proc~parse_cli_config parse_cli_config proc~parse_cli_config->proc~parse_cli

Source Code

   function quote_arg(a) result(q)
      character(len=*), intent(in) :: a
      character(len=:), allocatable :: q
      if (is_windows_os()) then
         q = '"' // escape_quotes_win(trim(a)) // '"'
      else
         q = "'" // escape_quotes_sh(trim(a)) // "'"
      end if
   contains
      pure function escape_quotes_win(s) result(r)
         character(len=*), intent(in) :: s
         character(len=:), allocatable :: r
         integer :: j
         r = ""
         do j = 1, len_trim(s)
            if (s(j:j) == '"') then
               r = r // '""'
            else
               r = r // s(j:j)
            end if
         end do
      end function escape_quotes_win

      pure function escape_quotes_sh(s) result(r)
         character(len=*), intent(in) :: s
         character(len=:), allocatable :: r
         integer :: j
         r = ""
         do j = 1, len_trim(s)
            if (s(j:j) == "'") then
               r = r // "'""'""'"
            else
               r = r // s(j:j)
            end if
         end do
      end function escape_quotes_sh
   end function quote_arg