add_stream_attributes Subroutine

private pure subroutine add_stream_attributes(self, attributes_stream, sanitize_values)

Add list of attributes name/value pairs passed as stream.

Note

The character = cannot compare into the attributes names of values.

Type Bound

xml_tag

Arguments

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

XML tag.

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

Attribute name/value pair list passed as stream.

logical, intent(in), optional :: sanitize_values

Sanitize attribute values.


Calls

proc~~add_stream_attributes~~CallsGraph proc~add_stream_attributes xml_tag%add_stream_attributes fill fill proc~add_stream_attributes->fill partition partition proc~add_stream_attributes->partition proc~add_single_attribute xml_tag%add_single_attribute proc~add_stream_attributes->proc~add_single_attribute slice slice proc~add_stream_attributes->slice proc~alloc_attributes xml_tag%alloc_attributes proc~add_single_attribute->proc~alloc_attributes

Called by

proc~~add_stream_attributes~~CalledByGraph proc~add_stream_attributes xml_tag%add_stream_attributes none~add_attributes xml_tag%add_attributes none~add_attributes->proc~add_stream_attributes proc~set xml_tag%set 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_stream_attributes(self, attributes_stream, sanitize_values)
   !< Add list of attributes name/value pairs passed as stream.
   !<
   !< @note The character `=` cannot compare into the attributes names of values.
   class(xml_tag), intent(inout)        :: self              !< XML tag.
   character(*),   intent(in)           :: attributes_stream !< Attribute name/value pair list passed as stream.
   logical,        intent(in), optional :: sanitize_values   !< Sanitize attribute values.
   type(string)                         :: attributes_string !< Attribute name/value pair list as string.
   type(string)                         :: tokens(1:3)       !< Attributes tokenized by `=`.
   type(string)                         :: attribute(1:2)    !< Attribute name/value pair.
   logical                              :: continue_to_parse !< Sentinel to stop attributes stream parsing.
   integer(I4P)                         :: max_chars         !< Counter.

   attributes_string = attributes_stream
   continue_to_parse = .true.
   do while(continue_to_parse)
      tokens = attributes_string%partition(sep='=')
      attribute(1) = trim(adjustl(tokens(1)))
      if (attribute(1)/='') then
         tokens(3) = tokens(3)%slice(istart=tokens(3)%index('"')+1, iend=tokens(3)%len())
         attribute(2) = tokens(3)%slice(istart=1, iend=tokens(3)%index('"')-1)
         tokens(3) = tokens(3)%slice(istart=tokens(3)%index('"')+1, iend=tokens(3)%len())
         max_chars = max(attribute(1)%len(), attribute(2)%len())
         attribute(1) = attribute(1)%fill(width=max_chars, right=.true., filling_char=' ')
         attribute(2) = attribute(2)%fill(width=max_chars, right=.true., filling_char=' ')
         call self%add_single_attribute(attribute=[attribute(1)//'', attribute(2)//''], sanitize_value=sanitize_values)
         if (tokens(3)%index('=')>0) then
            attributes_string = tokens(3)
         else
            continue_to_parse = .false.
         endif
      else
         continue_to_parse = .false.
      endif
   enddo
   endsubroutine add_stream_attributes