search Subroutine

private 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.

Type Bound

xml_tag

Arguments

Type IntentOptional 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.


Calls

proc~~search~~CallsGraph proc~search xml_tag%search is_allocated is_allocated proc~search->is_allocated proc~parse xml_tag%parse proc~search->proc~parse proc~parse->is_allocated proc~get xml_tag%get proc~parse->proc~get proc~parse_attributes_names xml_tag%parse_attributes_names proc~parse->proc~parse_attributes_names proc~parse_tag_name xml_tag%parse_tag_name proc~parse->proc~parse_tag_name proc~get_attributes xml_tag%get_attributes proc~get->proc~get_attributes proc~get_value xml_tag%get_value proc~get->proc~get_value proc~alloc_attributes xml_tag%alloc_attributes proc~parse_attributes_names->proc~alloc_attributes

Called by

proc~~search~~CalledByGraph proc~search xml_tag%search proc~get_content xml_tag%get_content proc~get_content->proc~search proc~content xml_file%content proc~content->proc~get_content

Source Code

   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)                          :: tstart_  !< Starting index of tag inside the source, local variable.
   integer(I4P)                          :: tend_    !< Ending index of tag inside the source, local variable.
   logical                               :: found    !< Flag for inquiring search result.
   integer(I4P)                          :: tstart_c !< Starting index of tag inside the current slice of source.
   integer(I4P)                          :: tend_c   !< Starting index of tag inside the current slice of source.
   integer(I4P)                          :: i

   call self%free
   self%tag_name = tag_name
   tstart_ = 1
   tend_   = 0
   found = .false.
   tstart_c = 0
   tend_c = 0
   tag_search: do
      call tag%parse(source=source(tend_ + 1:), tstart=tstart_c, tend=tend_c)
      tstart_ = tstart_ + tend_
      tend_ = tend_ + tend_c
      if (tstart_c==0.and.tend_c==0) then
         exit tag_search ! no tag found
      else
         if (tag%tag_name%is_allocated()) then
            if (tag%tag_name==self%tag_name) found = .true.
         endif
      endif
      if (found) exit tag_search
   enddo tag_search
   if (found) then
      self = tag
   else
      call self%free
   endif
   if (present(tstart)) tstart = tstart_
   if (present(tend  )) tend   = tend_
   endsubroutine search