end_with Function

private elemental function end_with(self, suffix, start, end)

Arguments

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

The string.

character(kind=CK,len=*), intent(in) :: suffix

Searched suffix.

integer, intent(in), optional :: start

Start position into the string.

integer, intent(in), optional :: end

End position into the string.

Return Value logical

Result of the test.

Description

Return true if a string ends with a specified suffix.


Variables

TypeVisibility AttributesNameInitial
integer, public :: start_

Start position into the string, local variable.

integer, public :: end_

End position into the string, local variable.


Source Code

  elemental function end_with(self, suffix, start, end)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Return true if a string ends with a specified suffix.
  !---------------------------------------------------------------------------------------------------------------------------------
  class(string),             intent(in)           :: self     !< The string.
  character(kind=CK, len=*), intent(in)           :: suffix   !< Searched suffix.
  integer,                   intent(in), optional :: start    !< Start position into the string.
  integer,                   intent(in), optional :: end      !< End position into the string.
  logical                                         :: end_with !< Result of the test.
  integer                                         :: start_   !< Start position into the string, local variable.
  integer                                         :: end_     !< End position into the string, local variable.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  end_with = .false.
  if (allocated(self%raw)) then
    start_ = 1             ; if (present(start)) start_ = start
    end_   = len(self%raw) ; if (present(end))   end_   = end
    if (len(suffix)<=len(self%raw(start_:end_))) then
      end_with = index(self%raw(start_:end_), suffix)==(len(self%raw(start_:end_)) - len(suffix) + 1)
    endif
  endif
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endfunction end_with