start_with Function

private elemental function start_with(self, prefix, start, end)

Arguments

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

The string.

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

Searched prefix.

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 starts with a specified prefix.


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 start_with(self, prefix, start, end)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Return true if a string starts with a specified prefix.
  !---------------------------------------------------------------------------------------------------------------------------------
  class(string),             intent(in)           :: self       !< The string.
  character(kind=CK, len=*), intent(in)           :: prefix     !< Searched prefix.
  integer,                   intent(in), optional :: start      !< Start position into the string.
  integer,                   intent(in), optional :: end        !< End position into the string.
  logical                                         :: start_with !< Result of the test.
  integer                                         :: start_     !< Start position into the string, local variable.
  integer                                         :: end_       !< End position into the string, local variable.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  start_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(prefix)<=len(self%raw(start_:end_))) then
      start_with = index(self%raw(start_:end_), prefix)==1
    endif
  endif
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endfunction start_with