C.3.1 Capitalize_Text_Utils Procedure

The main documentation of the Capitalize_Text_Utils Procedure contains additional explanation of this code listing.

  function Capitalize_Text_Utils (String) result(Capitalize)

    ! Input variables.

    type(character,*), intent(in) :: String         ! String to be capitalized.

    ! Output variables.

    type(character,255) :: Capitalize   ! The capitalize version of the string.

    ! Internal variables.

    type(integer) :: letter     ! Loop counter.
    type(logical) :: new_word   ! True if the next character starts a new word.

    !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    ! Verify requirements.

    VERIFY(Valid_State(String),5)          ! String is valid.

    ! Loop through letters, setting capitalized version.

    Capitalize = ' '
    new_word = .true.
    do letter = 1, LEN_TRIM(String)
      if (new_word) then
        Capitalize(letter:letter) = Uppercase(String(letter:letter))
      else
        Capitalize(letter:letter) = Lowercase(String(letter:letter))
      end if
      new_word = &
        (ICHAR(String(letter:letter)) .NotInInterval. Majuscules) .AND. &
        (ICHAR(String(letter:letter)) .NotInInterval. Minuscules)
    end do

    ! Verify guarantees.

    VERIFY(Valid_State(Capitalize),5)  ! Capitalize is valid.

    return
  end function Capitalize_Text_Utils



Michael L. Hall