enum_parse Subroutine

private subroutine enum_parse(this, values, err_msg)

Type Bound

nml_enum_key_t

Arguments

Type IntentOptional Attributes Name
class(nml_enum_key_t), intent(inout) :: this
character(len=*), intent(in) :: values(:)
character(len=:), intent(out), allocatable :: err_msg

Calls

proc~~enum_parse~~CallsGraph proc~enum_parse nml_enum_key_t%enum_parse proc~fmt_int fmt_int proc~enum_parse->proc~fmt_int proc~lower lower proc~enum_parse->proc~lower

Variables

Type Visibility Attributes Name Initial
integer, private :: i
character(len=:), private, allocatable :: list
character(len=:), private, allocatable :: v

Source Code

   subroutine enum_parse(this, values, err_msg)
      class(nml_enum_key_t), intent(inout) :: this
      character(len=*), intent(in) :: values(:)
      character(len=:), allocatable, intent(out) :: err_msg
      character(len=:), allocatable :: v, list
      integer :: i

      if (size(values) /= 1) then
         err_msg = "key '"//this%name//"' expects 1 value, got "//fmt_int(size(values))
         return
      end if
      v = trim(adjustl(values(1)))
      do i = 1, size(this%allowed)
         if (lower(v) == lower(trim(this%allowed(i)))) then
            if (len(trim(this%allowed(i))) > len(this%tgt)) then
               err_msg = "key '"//this%name//"': canonical value '"//trim(this%allowed(i))// &
                         "' exceeds target length "//fmt_int(len(this%tgt))
               return
            end if
            this%tgt = trim(this%allowed(i))
            return
         end if
      end do
      ! A spelling that WAS legal gets the migration message, never the
      ! generic allowed-set one: "not in allowed set" tells the reader the
      ! value is wrong but not what it is called now, which for a rename is
      ! the only thing they need.
      if (allocated(this%retired)) then
         do i = 1, size(this%retired)
            if (lower(v) == lower(trim(this%retired(i)))) then
               err_msg = "key '"//this%name//"': '"//v//"' was RETIRED"
               if (allocated(this%retired_hint)) then
                  err_msg = err_msg//" — "//this%retired_hint
               end if
               return
            end if
         end do
      end if
      list = ""
      do i = 1, size(this%allowed)
         if (i > 1) list = list//", "
         list = list//"'"//trim(this%allowed(i))//"'"
      end do
      err_msg = "key '"//this%name//"': '"//v//"' not in allowed set {"//list//"}"
   end subroutine enum_parse