startcase Function

private elemental function startcase(self, sep)

Arguments

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

The string.

character(kind=CK,len=*), intent(in), optional :: sep

Separator.

Return Value type(string)

Start case string.

Description

Return a string with all words capitalized, e.g. title case.


Variables

TypeVisibility AttributesNameInitial
character(kind=CK,len=:), public, allocatable:: sep_

Separator, default value.

type(string), public, allocatable:: tokens(:)

String tokens.


Source Code

  elemental function startcase(self, sep)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Return a string with all words capitalized, e.g. title case.
  !<
  !< @note Multiple subsequent separators are collapsed to one occurence.
  !---------------------------------------------------------------------------------------------------------------------------------
  class(string),             intent(in)           :: self      !< The string.
  character(kind=CK, len=*), intent(in), optional :: sep       !< Separator.
  type(string)                                    :: startcase !< Start case string.
  character(kind=CK, len=:), allocatable          :: sep_      !< Separator, default value.
  type(string), allocatable                       :: tokens(:) !< String tokens.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  if (allocated(self%raw)) then
    sep_ = SPACE ; if (present(sep)) sep_ = sep
    call self%split(tokens=tokens, sep=sep_)
    tokens = tokens%capitalize()
    startcase = startcase%join(array=tokens, sep=sep_)
  endif
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endfunction startcase