subroutinesplit_stringpureprivate
pure subroutine split_string(text, separator, v)
text.split(separator).
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| text | character(len=*) | in | the string | |
| separator | character(len=*) | in | what separates the parts | |
| v | type(value_t) | out | the result |
Calls
Source
Show the code
pure subroutine split_string(text, separator, v)
character(len=*), intent(in) :: text !! the string
character(len=*), intent(in) :: separator !! what separates the parts
type(value_t), intent(out) :: v !! the result
integer :: n, at, found, k
n = 1
at = 1
do
found = index(text(at:), separator)
if (found == 0) exit
n = n + 1
at = at + found - 1 + len(separator)
end do
v%kind = V_LIST
allocate (v%items(n))
at = 1
do k = 1, n
found = index(text(at:), separator)
if (found == 0) then
call make_string(text(at:), v%items(k))
else
call make_string(text(at:at + found - 2), v%items(k))
at = at + found - 1 + len(separator)
end if
end do
end subroutine split_string