strip Function

private elemental function strip(self, remove_nulls)

Arguments

Type IntentOptional AttributesName
class(string), intent(in) :: self

The string.

logical, intent(in), optional :: remove_nulls

Remove null characters at the end.

Return Value type(string)

The stripped string.

Description

Return a copy of the string with the leading and trailing characters removed.


Variables

TypeVisibility AttributesNameInitial
integer, public :: c

Counter.


Source Code

  elemental function strip(self, remove_nulls)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Return a copy of the string with the leading and trailing characters removed.
  !---------------------------------------------------------------------------------------------------------------------------------
  class(string), intent(in)           :: self         !< The string.
  logical,       intent(in), optional :: remove_nulls !< Remove null characters at the end.
  type(string)                        :: strip        !< The stripped string.
  integer                             :: c            !< Counter.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  if (allocated(self%raw)) then
    strip = self%adjustl()
    strip = strip%trim()
    if (present(remove_nulls)) then
      if (remove_nulls) then
        c = index(self%raw, char(0))
        if (c>0) strip%raw = strip%raw(1:c-1)
      endif
    endif
  endif
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endfunction strip