Return a string with all words capitalized without spaces.
Multiple subsequent separators are collapsed to one occurence.
type(string) :: astring
astring = 'caMeL caSe var'
print '(L1)', astring%camelcase()//''=='CamelCaseVar'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
Camel case string.
elemental function camelcase(self, sep)
!< Return a string with all words capitalized without spaces.
!<
!< @note Multiple subsequent separators are collapsed to one occurence.
!<
!<```fortran
!< type(string) :: astring
!< astring = 'caMeL caSe var'
!< print '(L1)', astring%camelcase()//''=='CamelCaseVar'
!<```
!=> T <<<
class(string), intent(in) :: self !< The string.
character(kind=CK, len=*), intent(in), optional :: sep !< Separator.
type(string) :: camelcase !< Camel case string.
type(string), allocatable :: tokens(:) !< String tokens.
if (allocated(self%raw)) then
call self%split(tokens=tokens, sep=sep)
tokens = tokens%capitalize()
camelcase = camelcase%join(array=tokens)
endif
endfunction camelcase