Sha256: 141f075d4c36bcee72c16b3c998228027eebf1f2aee65c646e49b3f9d621408c

Contents?: true

Size: 1.99 KB

Versions: 10

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: false
require_relative "baseparser"

module REXML
  module Parsers
    class StreamParser
      def initialize source, listener
        @listener = listener
        @parser = BaseParser.new( source )
        @entities = {}
      end

      def add_listener( listener )
        @parser.add_listener( listener )
      end

      def entity_expansion_count
        @parser.entity_expansion_count
      end

      def entity_expansion_limit=( limit )
        @parser.entity_expansion_limit = limit
      end

      def entity_expansion_text_limit=( limit )
        @parser.entity_expansion_text_limit = limit
      end

      def parse
        # entity string
        while true
          event = @parser.pull
          case event[0]
          when :end_document
            return
          when :start_element
            attrs = event[2].each do |n, v|
              event[2][n] = @parser.unnormalize( v )
            end
            @listener.tag_start( event[1], attrs )
          when :end_element
            @listener.tag_end( event[1] )
          when :text
            unnormalized = @parser.unnormalize( event[1], @entities )
            @listener.text( unnormalized )
          when :processing_instruction
            @listener.instruction( *event[1,2] )
          when :start_doctype
            @listener.doctype( *event[1..-1] )
          when :end_doctype
            # FIXME: remove this condition for milestone:3.2
            @listener.doctype_end if @listener.respond_to? :doctype_end
          when :comment, :attlistdecl, :cdata, :xmldecl, :elementdecl
            @listener.send( event[0].to_s, *event[1..-1] )
          when :entitydecl, :notationdecl
            @entities[ event[1] ] = event[2] if event.size == 3
            @listener.send( event[0].to_s, event[1..-1] )
          when :externalentity
            entity_reference = event[1]
            content = entity_reference.gsub(/\A%|;\z/, "")
            @listener.entity(content)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
brakeman-7.0.0 bundle/ruby/3.1.0/gems/rexml-3.4.0/lib/rexml/parsers/streamparser.rb
rexml-3.4.0 lib/rexml/parsers/streamparser.rb
cloudsmith-api-2.0.16 vendor/bundle/ruby/2.6.0/gems/rexml-3.3.9/lib/rexml/parsers/streamparser.rb
rexml-3.3.9 lib/rexml/parsers/streamparser.rb
brakeman-6.2.2 bundle/ruby/3.1.0/gems/rexml-3.3.8/lib/rexml/parsers/streamparser.rb
brakeman-6.2.2.rc1 bundle/ruby/3.3.0/gems/rexml-3.3.8/lib/rexml/parsers/streamparser.rb
cloudsmith-api-2.0.15 vendor/bundle/ruby/2.6.0/gems/rexml-3.3.8/lib/rexml/parsers/streamparser.rb
cloudsmith-api-2.0.14 vendor/bundle/ruby/2.6.0/gems/rexml-3.3.8/lib/rexml/parsers/streamparser.rb
rexml-3.3.8 lib/rexml/parsers/streamparser.rb
rexml-3.3.7 lib/rexml/parsers/streamparser.rb