Parse current tag, only name and attributes.
Type | Intent | Optional | 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. |
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