parse_attributes_names Subroutine

private elemental subroutine parse_attributes_names(self, source)

Arguments

Type IntentOptional AttributesName
class(xml_tag), intent(inout) :: self

XML tag.

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

String containing the input.

Description

Parse the tag attributes names contained into a string.

Valid syntax is: + att1="att1 val" att2="att2 val"...


Variables

TypeVisibility AttributesNameInitial
character(len=:), public, allocatable:: att

Dummy string for parsing file.

integer(kind=I4P), public :: c

Counter.

integer(kind=I4P), public :: s

Counter.

integer(kind=I4P), public :: a

Counter.

integer(kind=I4P), public :: Na

Counter.


Source Code

  elemental subroutine parse_attributes_names(self, source)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Parse the tag attributes names contained into a string.
  !<
  !< Valid syntax is:
  !< + `att1="att1 val" att2="att2 val"...`
  !< @note Inside the attributes value the symbols `<` and `>` are not allowed.
  !---------------------------------------------------------------------------------------------------------------------------------
  class(xml_tag), intent(inout) :: self   !< XML tag.
  character(*),   intent(in)    :: source !< String containing the input.
  character(len=:), allocatable :: att    !< Dummy string for parsing file.
  integer(I4P)                  :: c      !< Counter.
  integer(I4P)                  :: s      !< Counter.
  integer(I4P)                  :: a      !< Counter.
  integer(I4P)                  :: Na     !< Counter.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  Na = 0
  c = 1
  Att_Count: do while(c<=len(source))
    if (source(c:c)=='=') Na = Na + 1
    c = c + 1
  enddo Att_Count
  if (Na>0) then
    call self%alloc_attributes(Na=Na)
    c = index(string=source, substring=' ')
    att = source(c:)
    c = 1
    a = 1
    Att_Search: do while(c<=len(att))
      if (att(c:c)=='=') then
        s = max(0, index(string=att, substring=' '))
        self%attribute(1, a) = trim(adjustl(att(s+1:c-1)))
        att = att(c+1:)
        c = 1
        a = a + 1
      endif
      c = c + 1
    enddo Att_Search
  endif
  !---------------------------------------------------------------------------------------------------------------------------------
  endsubroutine parse_attributes_names