Parse a string into tokens. This subroutine implements the tokenize intrinsic procedure as defined in
the Fortran 2023 language standard (Section 16.9.210).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | string | |||
| character(len=*), | intent(in) | :: | set | |||
| character(len=:), | intent(out), | allocatable | :: | tokens(:) | ||
| character(len=:), | intent(out), | optional, | allocatable | :: | separator(:) |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private, | allocatable | :: | first(:) | |||
| integer, | private | :: | i | ||||
| integer, | private, | allocatable | :: | last(:) | |||
| integer, | private | :: | n |
pure subroutine tokenize_into_tokens_separator(string, set, tokens, separator) character(*), intent(in) :: string, set character(:), allocatable, intent(out) :: tokens(:) character(:), allocatable, optional, intent(out) :: separator(:) integer, allocatable :: first(:), last(:) integer :: i, n call tokenize(string, set, first, last) n = size(first) allocate(character(maxval(last - first) + 1) :: tokens(n)) do i = 1, n tokens(i) = string(first(i):last(i)) end do if (present(separator)) then allocate(character(1) :: separator(n - 1)) do i = 1, n - 1 separator(i) = string(last(i) + 1:last(i) + 1) end do end if end subroutine tokenize_into_tokens_separator