startcase Function

private elemental function startcase(self, sep)

Type Bound

string

Arguments

Type IntentOptional Attributes Name
class(string), intent(in) :: self
character(kind=CK, len=*), intent(in), optional :: sep

Return Value type(string)


Calls

proc~~startcase~2~~CallsGraph proc~startcase~2 string%startcase none~join~8 string%join proc~startcase~2->none~join~8 proc~capitalize~2 string%capitalize proc~startcase~2->proc~capitalize~2 proc~split~2 string%split proc~startcase~2->proc~split~2 proc~join_characters~2 string%join_characters none~join~8->proc~join_characters~2 proc~join_strings~2 string%join_strings none~join~8->proc~join_strings~2 proc~lower~2 string%lower proc~capitalize~2->proc~lower~2 proc~partition~2 string%partition proc~split~2->proc~partition~2 proc~unique~2 string%unique proc~split~2->proc~unique~2 proc~replace~2 string%replace proc~unique~2->proc~replace~2 proc~replace_one_occurrence~2 string%replace_one_occurrence proc~replace~2->proc~replace_one_occurrence~2

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.
   !<
   !<```fortran
   !< type(string) :: astring
   !< logical      :: test_passed(1)
   !< astring = 'the Quick Brown fox Jumps over the Lazy Dog.'
   !< test_passed(1) = astring%startcase()//''=='The Quick Brown Fox Jumps Over The Lazy Dog.'
   !< print '(L1)', all(test_passed)
   !<```
   !=> T <<<
   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
   endfunction startcase