3 ! Make sure that PR82617 remains fixed. The first attempt at a
4 ! fix for PR70752 cause this to ICE at the point indicated below.
6 ! Contributed by Ogmundur Petersson <uberprugelknabe@hotmail.com>
15 !> Characters that are considered whitespace.
16 CHARACTER(len
=*), PARAMETER :: strwhitespace
= &
18 char(10)//& ! new line
19 char(13)//& ! carriage return
20 char( 9)//& ! horizontal tab
21 char(11)//& ! vertical tab
22 char(12) ! form feed (new page)
26 ! -------------------------------------------------------------------
27 !> Split string into words separated by arbitrary strings of whitespace
28 !> characters (space, tab, newline, return, formfeed).
29 FUNCTION str_words(str
,white
) RESULT(items
)
30 CHARACTER(len
=:), DIMENSION(:), ALLOCATABLE
:: items
31 CHARACTER(len
=*), INTENT(in
) :: str
!< String to split.
32 CHARACTER(len
=*), INTENT(in
) :: white
! Whitespace characters.
34 items
= strwords_impl(str
,white
)
36 END FUNCTION str_words
38 ! -------------------------------------------------------------------
39 !>Implementation of str_words
40 !> characters (space, tab, newline, return, formfeed).
41 FUNCTION strwords_impl(str
,white
) RESULT(items
)
42 CHARACTER(len
=:), DIMENSION(:), ALLOCATABLE
:: items
43 CHARACTER(len
=*), INTENT(in
) :: str
!< String to split.
44 CHARACTER(len
=*), INTENT(in
) :: white
! Whitespace characters.
47 INTEGER :: l_item
,i_item
,n_item
49 n
= verify(str
,white
,.TRUE
.)
55 i0
= verify(str(i1
+1:n
),white
)+i1
56 i1
= scan(str(i0
+1:n
),white
)
59 l_item
= max(l_item
,i1
)
62 l_item
= max(l_item
,n
-i0
+1)
66 ALLOCATE(CHARACTER(len
=l_item
)::items(n_item
))
70 i0
= verify(str(i1
+1:n
),white
)+i1
71 i1
= scan(str(i0
+1:n
),white
)
75 items(i_item
) = str(i0
:i1
-1)
77 items(i_item
) = str(i0
:n
)
82 ALLOCATE(CHARACTER(len
=0)::items(0))
85 END FUNCTION strwords_impl