suggest Function

private function suggest(name, candidates) result(msg)

Build a ” (did you mean ‘x’?)” fragment if a close candidate exists (distance <= max(2, len/3)); else empty.

Arguments

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

Return Value character(len=:), allocatable


Calls

proc~~suggest~~CallsGraph proc~suggest suggest proc~levenshtein levenshtein proc~suggest->proc~levenshtein proc~lower lower proc~suggest->proc~lower

Called by

proc~~suggest~~CalledByGraph proc~suggest suggest proc~apply_one_pair apply_one_pair proc~apply_one_pair->proc~suggest proc~dispatch_group dispatch_group proc~dispatch_group->proc~suggest 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~dispatch_group proc~parse_group_body->proc~apply_one_pair 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 :: best_d
integer, private :: best_i
integer, private :: d
integer, private :: i
integer, private :: thresh

Source Code

   function suggest(name, candidates) result(msg)
      !! Build a " (did you mean 'x'?)" fragment if a close candidate
      !! exists (distance <= max(2, len/3)); else empty.
      character(len=*), intent(in) :: name
      character(len=*), intent(in) :: candidates(:)
      character(len=:), allocatable :: msg
      integer :: i, d, best_d, best_i, thresh

      msg = ""
      best_d = huge(0)
      best_i = 0
      thresh = max(2, len_trim(name)/3)
      do i = 1, size(candidates)
         d = levenshtein(lower(trim(name)), lower(trim(candidates(i))))
         if (d < best_d) then
            best_d = d
            best_i = i
         end if
      end do
      if (best_i > 0 .and. best_d <= thresh) then
         msg = " (did you mean '"//trim(candidates(best_i))//"'?)"
      end if
   end function suggest