Manual Reference Pages  - ends_with (3m_strings)

NAME

ends_with(3f) - [M_strings:COMPARE] test if string ends with specified suffix(es) (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

pure function ends_with(source_string[,suffix][,ignorecase])

    character(len=*),intent(in)          :: source_string
    character(len=*),intent(in)          :: suffix(..)
    logical,intent(in),optional          :: ignorecase
    logical                              :: ends_with

DESCRIPTION

ends_with(3f) tests if a string ends with any specified suffix. Differs from using index(3f) in that the input file and multiple suffices are trimmed by ends_with(3f),

OPTIONS

SOURCE_STRING
  string to search
SUFFIX list of separator strings. May be scalar or an array. Trailing spaces in SUFFIX are ignored.
IGNORECASE
  If .true. case is ignored.

RETURNS

ENDS_WITH
  returns .TRUE. if one of the suffix match the end of SOURCE_STRING.

EXAMPLES

Sample program:

   program demo_ends_with
   use M_strings, only : ends_with
   use, intrinsic :: iso_fortran_env, only : stdout=>output_unit
   implicit none
   character(len=:),allocatable :: line, pattern
   !
      write(*,*)’basic usage’
      write(stdout,*)ends_with(’prog.a’,’.a’), ’should be true’
      write(stdout,*)ends_with(’prog.a’,’.o’), ’should be false’
      write(stdout,*)ends_with(’prog.a’,[’.o’,’.i’,’.s’])
      write(stdout,*)ends_with(’prog.f90’,[’.F90’,’.f90’,’.f  ’,’.F  ’])
      !
      write(*,*)’ignored case’
      write(stdout,*)ends_with(’prog.F90’,[’.f90’,’.f  ’],ignorecase=.true.)
      !
      write(*,*)’trailing whitespace is ignored’
      write(stdout,*)ends_with(’prog.pdf’,’.pdf’)
      write(stdout,*)ends_with(’prog.pdf’,’.pdf ’)
      write(stdout,*)ends_with(’prog.pdf ’,’.pdf ’)
      write(stdout,*)ends_with(’prog.pdf  ’,’.pdf ’)
      !
      write(*,*)’equivalent using index(3f)’
      line=   ’myfile.doc  ’
      pattern=’.doc        ’
      write(stdout,*)&
      &index(trim(line),trim(pattern),back=.true.)==len_trim(line)-len_trim(pattern)+1
      write(stdout,*)ends_with(line,pattern)
   end program demo_ends_with

Results:

    >  basic usage
    >  T should be true
    >  F should be false
    >  F
    >  T
    >  ignored case
    >  T
    >  trailing whitespace is ignored
    >  T
    >  T
    >  T
    >  T
    >  equivalent using index(3f)
    >  T
    >  T

AUTHOR

John S. Urban

LICENSE

Public Domain


Nemo Release 3.1 ends_with (3m_strings) July 20, 2024
Generated by manServer 1.08 from 410d4d05-a25f-48d7-bd82-aa1f95a48b57 using man macros.