replace_delimiter Function

public function replace_delimiter(string, delimiter, replacement) result(replaced)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: string
character(len=*), intent(in), optional :: delimiter
character(len=*), intent(in), optional :: replacement

Return Value character(len=:), allocatable


Called by

proc~~replace_delimiter~~CalledByGraph proc~replace_delimiter replace_delimiter proc~get_expression_variables get_expression_variables proc~get_expression_variables->proc~replace_delimiter proc~test_replace_delimiter test_replace_delimiter proc~test_replace_delimiter->proc~replace_delimiter proc~test_get_expression_variables test_get_expression_variables proc~test_get_expression_variables->proc~get_expression_variables

Source Code

   function replace_delimiter(string, delimiter, replacement) result(replaced)
      character(len=:), allocatable :: replaced
      character(len=*), intent(in) :: string
      character(len=*), optional, intent(in) :: delimiter
      character(len=*), optional, intent(in) :: replacement
      character(len=:), allocatable :: del, rep
      integer :: i

      replaced = string
      if(len(string) == 0) return

      del = '.'
      if(present(delimiter)) del = delimiter
      if(len(del) == 0) return

      rep = '/'
      if(present(replacement)) rep = replacement
      if(len(rep) == 0) return

      i = index(replaced, del)
      if(i > 0) replaced = replaced(:(i-1))// rep // replaced((i+len(del)):)

   end function replace_delimiter