get_tag_content Subroutine

private pure subroutine get_tag_content(source, tag_name, start_pos, content, end_pos)

Get tag content.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: source

Source containing tag content.

character(len=*), intent(in) :: tag_name

Tag name.

integer, intent(in) :: start_pos

Start tag content position.

character(len=:), intent(out), allocatable :: content

Extracted tag content.

integer(kind=I4P), intent(out), optional :: end_pos

End tag content position.


Calls

proc~~get_tag_content~~CallsGraph proc~get_tag_content get_tag_content proc~find_matching_end_tag find_matching_end_tag proc~get_tag_content->proc~find_matching_end_tag

Called by

proc~~get_tag_content~~CalledByGraph proc~get_tag_content get_tag_content proc~parse_from_string xml_file%parse_from_string proc~parse_from_string->proc~get_tag_content proc~parse~2 xml_file%parse proc~parse~2->proc~parse_from_string program~foxy_test_delete_tag foxy_test_delete_tag program~foxy_test_delete_tag->proc~parse~2 program~foxy_test_parse_file_simple foxy_test_parse_file_simple program~foxy_test_parse_file_simple->proc~parse~2 program~foxy_test_parse_string_nested_tags foxy_test_parse_string_nested_tags program~foxy_test_parse_string_nested_tags->proc~parse~2 program~foxy_test_parse_string_simple foxy_test_parse_string_simple program~foxy_test_parse_string_simple->proc~parse~2 program~foxy_test_write_tag foxy_test_write_tag program~foxy_test_write_tag->proc~parse~2

Source Code

   pure subroutine get_tag_content(source, tag_name, start_pos, content, end_pos)
   !< Get tag content.
   character(*),              intent(in)            :: source       !< Source containing tag content.
   character(*),              intent(in)            :: tag_name     !< Tag name.
   integer,                   intent(in)            :: start_pos    !< Start tag content position.
   character(:), allocatable, intent(out)           :: content      !< Extracted tag content.
   integer(I4P),              intent(out), optional :: end_pos      !< End tag content position.
   character(:), allocatable                        :: end_tag      !< End tag.
   integer(I4P)                                     :: end_pos_     !< End tag content position, local var.
   integer(I4P)                                     :: next_pos     !< Next tag start position.
   character(:), allocatable                        :: temp_content !< Buffer.

   end_tag = '</'//trim(tag_name)//'>'
   content = ''

   call find_matching_end_tag(source=source, start_pos=start_pos, tag_name=tag_name, end_pos=end_pos_)

   if (present(end_pos)) end_pos = end_pos_
   if (end_pos_ > start_pos) then
      ! search first nested tag, if any
      next_pos = index(source(start_pos:end_pos_-1), '<')

      if (next_pos > 0) then
         ! find nested tag
         next_pos = start_pos + next_pos - 2
         temp_content = trim(adjustl(source(start_pos:next_pos)))
         if (len(temp_content) > 0) content = temp_content
      else
         ! no nested tag
         temp_content = trim(adjustl(source(start_pos:end_pos_-1)))
         if (len(temp_content) > 0) content = temp_content
      endif
   endif
   endsubroutine get_tag_content