Get section options from a source string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(section), | intent(inout) | :: | self | Section data. |
||
character, | intent(in) | :: | sep | Separator of option name/value. |
||
type(string), | intent(inout) | :: | source | String containing section data. |
||
integer(kind=I4P), | intent(out) | :: | error | Error code. |
elemental subroutine parse_options(self, sep, source, error)
!< Get section options from a source string.
class(section), intent(inout) :: self !< Section data.
character(*), intent(in) :: sep !< Separator of option name/value.
type(string), intent(inout) :: source !< String containing section data.
integer(I4P), intent(out) :: error !< Error code.
type(string), allocatable :: tokens(:) !< Options strings tokenized.
type(string) :: dummy !< Dummy string for parsing options.
integer(I4P) :: No !< Counter.
integer(I4P) :: o !< Counter.
integer(I4P) :: oo !< Counter.
error = 0
source = trim(adjustl(source%slice(index(source, "]")+1, source%len())))
No = source%count(substring=sep)
if (No>0) then
call source%split(tokens=tokens, sep=new_line('a'))
if (allocated(self%options)) deallocate(self%options) ; allocate(self%options(1:No))
o = 0
oo = 0
do while (o+1<=size(tokens, dim=1))
o = o + 1
if (index(tokens(o), sep)>0) then
oo = oo + 1
call self%options(oo)%parse(sep=sep, source=tokens(o), error=error)
endif
enddo
endif
endsubroutine parse_options