Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self | XML tag. |
||
character(len=*), | intent(in) | :: | tag_name | Searched tag name. |
||
character(len=*), | intent(in) | :: | source | String containing the input. |
||
integer(kind=I4P), | intent(out), | optional | :: | tstart | Starting index of tag inside the source. |
|
integer(kind=I4P), | intent(out), | optional | :: | tend | Ending index of tag inside the source. |
Search tag named tag_name into a string and, in case it is found, store into self.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(xml_tag), | public | :: | tag | Dummy XML tag. |
|||
integer(kind=I4P), | public | :: | tstartd | Starting index of tag inside the source. |
|||
integer(kind=I4P), | public | :: | tendd | Ending index of tag inside the source. |
|||
logical, | public | :: | found | Flag for inquiring search result. |
elemental subroutine search(self, tag_name, source, tstart, tend)
!---------------------------------------------------------------------------------------------------------------------------------
!< Search tag named *tag_name* into a string and, in case it is found, store into self.
!<
!< @note If *tag_name* is not found, self is returned empty.
!---------------------------------------------------------------------------------------------------------------------------------
class(xml_tag), intent(inout) :: self !< XML tag.
character(*), intent(in) :: tag_name !< Searched tag name.
character(*), intent(in) :: source !< String containing the input.
integer(I4P), optional, intent(out) :: tstart !< Starting index of tag inside the source.
integer(I4P), optional, intent(out) :: tend !< Ending index of tag inside the source.
type(xml_tag) :: tag !< Dummy XML tag.
integer(I4P) :: tstartd !< Starting index of tag inside the source.
integer(I4P) :: tendd !< Ending index of tag inside the source.
logical :: found !< Flag for inquiring search result.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
call self%free
self%tag_name = tag_name
tstartd = 1
tendd = 0
found = .false.
Tag_Search: do while ((.not.found).or.(len(source(tendd + 1:))<self%tag_name%len()))
call tag%parse(source=source(tendd + 1:), tstart=tstartd, tend=tendd)
if (tstartd==0.and.tendd==0) then
exit Tag_Search ! no tag found
else
if (tag%tag_name%is_allocated()) then
if (tag%tag_name==self%tag_name) then
found = .true.
endif
endif
endif
enddo Tag_Search
if (found) then
self = tag
else
call self%free
endif
if (present(tstart)) tstart = tstartd
if (present(tend )) tend = tendd
!---------------------------------------------------------------------------------------------------------------------------------
endsubroutine search