camelcase Function

private elemental function camelcase(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)

Camel case string.

Description

Return a string with all words capitalized without spaces.

Example

```fortran type(string) :: astring astring = 'caMeL caSe var' print '(A)', astring%camelcase()//'' ! print "CamelCaseVar"


Variables

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

String tokens.


Source Code

  elemental function camelcase(self, sep)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Return a string with all words capitalized without spaces.
  !<
  !< @note Multiple subsequent separators are collapsed to one occurence.
  !<
  !<### Example
  !<
  !<```fortran
  !< type(string) :: astring
  !< astring = 'caMeL caSe var'
  !< print '(A)', astring%camelcase()//'' ! print "CamelCaseVar"
  !---------------------------------------------------------------------------------------------------------------------------------
  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
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endfunction camelcase