delete_single_attribute Subroutine

private pure subroutine delete_single_attribute(self, name)

Arguments

TypeIntentOptionalAttributesName
class(xml_tag), intent(inout) :: self
character, intent(in) :: name

Contents


Source Code

  pure subroutine delete_single_attribute(self, name)
  !< Delete one attribute name/value pair.
  class(xml_tag), intent(inout) :: self               !< XML tag.
  character(*),   intent(in)    :: name               !< Attribute name.
  type(string), allocatable     :: new_attribute(:,:) !< Temporary storage for attributes.
  integer(I4P)                  :: a                  !< Counter.

  if (self%attributes_number>0) then
    search_tag: do a=1, self%attributes_number
      if (self%attribute(1, a)==name) then
        if (self%attributes_number>1) then
          allocate(new_attribute(1:2, 1:self%attributes_number-1))
          if (a==1) then
            new_attribute(:, a:) = self%attribute(:, a+1:)
          elseif (a==self%attributes_number) then
            new_attribute(:, :a-1) = self%attribute(:, :a-1)
          else
            new_attribute(:, :a-1) = self%attribute(:, :a-1)
            new_attribute(:, a:) = self%attribute(:, a+1:)
          endif
          call move_alloc(from=new_attribute, to=self%attribute)
        else
          call self%attribute%free
          deallocate(self%attribute)
        endif
        self%attributes_number = self%attributes_number - 1
        exit search_tag
      endif
    enddo search_tag
  endif
  endsubroutine delete_single_attribute