public pure subroutine split(string, set, pos, back)
Parse a string into tokens, one at a time. Each character in set is a token delimiter.
If back is absent or is present with the value .false., pos is assigned the position of the leftmost
token delimiter in string whose position is greater than pos, or if there is no such character, it
is assigned a value one greater than the length of string. This identifies a token with starting
position one greater than the value of pos on invocation, and ending position one less than the
value of pos on return.
If back is present with the value .true., pos is assigned the position of the rightmost token delimiter
in string whose position is less than pos, or if there is no such character, it is assigned the value
zero. This identifies a token with ending position one less than the value of pos on invocation, and
starting position one greater than the value of pos on return.
This subroutine implements the split intrinsic procedure as defined in the Fortran 2023 language standard
(Section 16.9.196). We implement it ourselves because the compiler support may take years to become widespread.
(KCW, 2025-10-29)
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Variables
Type
Visibility
Attributes
Name
Initial
integer,
private
::
offset
Source Code
pure subroutine split(string,set,pos,back)character(*),intent(in)::string,setinteger,intent(inout)::poslogical,optional,intent(in)::backinteger::offsetif(present(back))then if(back)thenoffset=clamp(pos,1,len(string)+1)pos=scan(string(1:offset-1),set,back=.true.)return end if end ifoffset=clamp(pos,0,len(string))pos=scan(string(offset+1:),set)if(pos==0)thenpos=len(string)+1return end ifpos=offset+posend subroutine split