capitalize Function

private elemental function capitalize(self) result(capitalized)

Arguments

Type IntentOptional AttributesName
class(string), intent(in) :: self

The string.

Return Value type(string)

Upper case string.

Description

Return a string with its first character capitalized and the rest lowercased.


Variables

TypeVisibility AttributesNameInitial
integer, public :: c

Character counter.


Source Code

  elemental function capitalize(self) result(capitalized)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Return a string with its first character capitalized and the rest lowercased.
  !---------------------------------------------------------------------------------------------------------------------------------
  class(string), intent(in) :: self        !< The string.
  type(string)              :: capitalized !< Upper case string.
  integer                   :: c           !< Character counter.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  if (allocated(self%raw)) then
    capitalized = self%lower()
    c = index(LOWER_ALPHABET, capitalized%raw(1:1))
    if (c>0) capitalized%raw(1:1) = UPPER_ALPHABET(c:c)
  endif
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endfunction capitalize