parse_tag_name Subroutine

private pure subroutine parse_tag_name(tag_str, tag_name, attributes_str, is_closing, is_self_closing)

Parse current tag, only name and attributes.

Arguments

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

Tag string.

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

Parsed tag name.

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

Parsed attributes list.

logical, intent(out) :: is_closing

Sentinel for closing tag.

logical, intent(out) :: is_self_closing

Sentinel for self closing tag.


Called by

proc~~parse_tag_name~2~~CalledByGraph proc~parse_tag_name~2 parse_tag_name proc~parse_from_string xml_file%parse_from_string proc~parse_from_string->proc~parse_tag_name~2 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 parse_tag_name(tag_str, tag_name, attributes_str, is_closing, is_self_closing)
   !< Parse current tag, only name and attributes.
   character(*),              intent(in)  :: tag_str         !< Tag string.
   character(:), allocatable, intent(out) :: tag_name        !< Parsed tag name.
   character(:), allocatable, intent(out) :: attributes_str  !< Parsed attributes list.
   logical,                   intent(out) :: is_closing      !< Sentinel for closing tag.
   logical,                   intent(out) :: is_self_closing !< Sentinel for self closing tag.
   character(:), allocatable              :: clean_tag       !< Clean tag string.
   integer(I4P)                           :: space_pos       !< Blank space position.

   clean_tag = trim(adjustl(tag_str))
   if (len(clean_tag) < 3) return

   ! trim < and >
   clean_tag = clean_tag(2:len(clean_tag)-1)

   is_self_closing = (clean_tag(len(clean_tag):len(clean_tag)) == '/')
   if (is_self_closing) then
      is_closing = .false.
   else
      is_closing = (clean_tag(1:1) == '/')
   endif

   if (is_closing) clean_tag = clean_tag(2:)

   if (is_self_closing) clean_tag = clean_tag(1:len(clean_tag)-1)

   ! parse name and attributes
   space_pos = index(clean_tag, ' ')
   if (space_pos > 0) then
      tag_name = clean_tag(1:space_pos-1)
      attributes_str = clean_tag(space_pos+1:)
   else
      tag_name = clean_tag
   endif
   endsubroutine parse_tag_name