diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb index 90b370b9..54eea54b 100644 --- a/lib/rexml/source.rb +++ b/lib/rexml/source.rb @@ -58,46 +58,9 @@ def encoding=(enc) encoding_updated end - # Scans the source for a given pattern. Note, that this is not your - # usual scan() method. For one thing, the pattern argument has some - # requirements; for another, the source can be consumed. You can easily - # confuse this method. Originally, the patterns were easier - # to construct and this method more robust, because this method - # generated search regexps on the fly; however, this was - # computationally expensive and slowed down the entire REXML package - # considerably, since this is by far the most commonly called method. - # @param pattern must be a Regexp, and must be in the form of - # /^\s*(#{your pattern, with no groups})(.*)/. The first group - # will be returned; the second group is used if the consume flag is - # set. - # @param consume if true, the pattern returned will be consumed, leaving - # everything after it in the Source. - # @return the pattern, if found, or nil if the Source is empty or the - # pattern is not found. - def scan(pattern, cons=false) - return nil if @buffer.nil? - rv = @buffer.scan(pattern) - @buffer = $' if cons and rv.size>0 - rv - end - def read end - def consume( pattern ) - @buffer = $' if pattern.match( @buffer ) - end - - def match_to( char, pattern ) - return pattern.match(@buffer) - end - - def match_to_consume( char, pattern ) - md = pattern.match(@buffer) - @buffer = $' - return md - end - def match(pattern, cons=false) md = pattern.match(@buffer) @buffer = $' if cons and md @@ -109,10 +72,6 @@ def empty? @buffer == "" end - def position - @orig.index( @buffer ) - end - # @return the current line in the source def current_line lines = @orig.split @@ -181,29 +140,6 @@ def initialize(arg, block_size=500, encoding=nil) end end - def scan(pattern, cons=false) - rv = super - # You'll notice that this next section is very similar to the same - # section in match(), but just a liiittle different. This is - # because it is a touch faster to do it this way with scan() - # than the way match() does it; enough faster to warrant duplicating - # some code - if rv.size == 0 - until @buffer =~ pattern or @source.nil? - begin - @buffer << readline - rescue Iconv::IllegalSequence - raise - rescue - @source = nil - end - end - rv = super - end - rv.taint if RUBY_VERSION < '2.7' - rv - end - def read begin @buffer << readline @@ -212,10 +148,6 @@ def read end end - def consume( pattern ) - match( pattern, true ) - end - def match( pattern, cons=false ) rv = pattern.match(@buffer) @buffer = $' if cons and rv @@ -236,10 +168,6 @@ def empty? super and ( @source.nil? || @source.eof? ) end - def position - @er_source.pos rescue 0 - end - # @return the current line in the source def current_line begin diff --git a/test/test_core.rb b/test/test_core.rb index 7c18c03f..cc22109d 100644 --- a/test/test_core.rb +++ b/test/test_core.rb @@ -721,22 +721,6 @@ def test_bad_content end end - def test_iso_8859_1_output_function - out = "" - output = Output.new( out ) - koln_iso_8859_1 = "K\xF6ln" - koln_utf8 = "K\xc3\xb6ln" - source = Source.new( koln_iso_8859_1, 'iso-8859-1' ) - results = source.scan(/.*/)[0] - koln_utf8.force_encoding('UTF-8') if koln_utf8.respond_to?(:force_encoding) - assert_equal koln_utf8, results - output << results - if koln_iso_8859_1.respond_to?(:force_encoding) - koln_iso_8859_1.force_encoding('ISO-8859-1') - end - assert_equal koln_iso_8859_1, out - end - def test_attributes_each doc = Document.new("") count = 0