Get tag content.
Type | Intent | Optional | 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. |
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