Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self | The string. |
||
character(kind=CK,len=*), | intent(in), | optional | :: | sep | Separator. |
Start case string.
Return a string with all words capitalized, e.g. title case.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(kind=CK,len=:), | public, | allocatable | :: | sep_ | Separator, default value. |
||
type(string), | public, | allocatable | :: | tokens(:) | String tokens. |
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