add_single_attribute Subroutine

private pure subroutine add_single_attribute(self, attribute, sanitize_value)

Add one attribute name/value pair.

Note

Leading and trailing white spaces are trimmed out by attribute's name.

Type Bound

xml_tag

Arguments

Type IntentOptional Attributes Name
class(xml_tag), intent(inout) :: self

XML tag.

character(len=*), intent(in) :: attribute(1:)

Attribute name/value pair [1:2].

logical, intent(in), optional :: sanitize_value

Sanitize attribute value.


Calls

proc~~add_single_attribute~~CallsGraph proc~add_single_attribute xml_tag%add_single_attribute proc~alloc_attributes xml_tag%alloc_attributes proc~add_single_attribute->proc~alloc_attributes

Called by

proc~~add_single_attribute~~CalledByGraph proc~add_single_attribute xml_tag%add_single_attribute none~add_attributes xml_tag%add_attributes none~add_attributes->proc~add_single_attribute proc~add_multiple_attributes xml_tag%add_multiple_attributes none~add_attributes->proc~add_multiple_attributes proc~add_stream_attributes xml_tag%add_stream_attributes none~add_attributes->proc~add_stream_attributes proc~add_multiple_attributes->proc~add_single_attribute proc~add_stream_attributes->proc~add_single_attribute proc~set xml_tag%set proc~set->proc~add_single_attribute proc~set->proc~add_multiple_attributes proc~set->proc~add_stream_attributes proc~create_tag_flat create_tag_flat proc~create_tag_flat->proc~set proc~create_tag_nested create_tag_nested proc~create_tag_nested->proc~set proc~parse_from_string xml_file%parse_from_string proc~parse_from_string->proc~set program~foxy_test_add_attributes foxy_test_add_attributes program~foxy_test_add_attributes->none~add_attributes program~foxy_test_create_tag foxy_test_create_tag program~foxy_test_create_tag->proc~set interface~xml_tag xml_tag interface~xml_tag->proc~create_tag_flat interface~xml_tag->proc~create_tag_nested 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 add_single_attribute(self, attribute, sanitize_value)
   !< Add one attribute name/value pair.
   !<
   !< @note Leading and trailing white spaces are trimmed out by attribute's name.
   class(xml_tag), intent(inout)        :: self               !< XML tag.
   character(*),   intent(in)           :: attribute(1:)      !< Attribute name/value pair [1:2].
   logical,        intent(in), optional :: sanitize_value     !< Sanitize attribute value.
   type(string), allocatable            :: new_attribute(:,:) !< Temporary storage for attributes.
   logical                              :: sanitize_value_    !< Sanitize attribute value.
   logical                              :: is_updated         !< Flag to check if the attribute has been updeted.
   integer(I4P)                         :: a                  !< Counter.

   sanitize_value_ = .false. ; if (present(sanitize_value)) sanitize_value_ = sanitize_value
   if (self%attributes_number>0) then
      is_updated = .false.
      update_if_already_present: do a=1, self%attributes_number
         if (self%attribute(1, a)==attribute(1)) then
            if (sanitize_value_) then
               self%attribute(2, a) = trim(adjustl(attribute(2)))
            else
               self%attribute(2, a) = attribute(2)
            endif
            is_updated = .true.
            exit update_if_already_present
         endif
      enddo update_if_already_present
      if (.not.is_updated) then
         allocate(new_attribute(1:2, 1:self%attributes_number+1))
         new_attribute(1:2, 1:self%attributes_number) = self%attribute
         new_attribute(1, self%attributes_number+1) = trim(adjustl(attribute(1)))
         if (sanitize_value_) then
            new_attribute(2, self%attributes_number+1) = trim(adjustl(attribute(2)))
         else
            new_attribute(2, self%attributes_number+1) = attribute(2)
         endif
         call move_alloc(from=new_attribute, to=self%attribute)
         self%attributes_number = self%attributes_number + 1
      endif
   else
      call self%alloc_attributes(Na=1)
      self%attribute(1, 1) = trim(adjustl(attribute(1)))
      if (sanitize_value_) then
         self%attribute(2, 1) = trim(adjustl(attribute(2)))
      else
         self%attribute(2, 1) = attribute(2)
      endif
   endif
   endsubroutine add_single_attribute