snakecase Function

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

Snake case string.

Description

Return a string with all words lowercase separated by "_".


Variables

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

String tokens.


Source Code

  elemental function snakecase(self, sep)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Return a string with all words lowercase separated by "_".
  !<
  !< @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)                                    :: snakecase !< Snake case string.
  type(string), allocatable                       :: tokens(:) !< String tokens.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  if (allocated(self%raw)) then
    call self%split(tokens=tokens, sep=sep)
    tokens = tokens%lower()
    snakecase = snakecase%join(array=tokens, sep='_')
  endif
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endfunction snakecase