Skip to content

Commit

Permalink
Change StringScanner.new to a call in the initialize method.
Browse files Browse the repository at this point in the history
  • Loading branch information
naitoh committed Jan 13, 2024
1 parent c2f47ab commit c87e1ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 6 additions & 8 deletions lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ def pull_event
unless md
raise REXML::ParseException.new("malformed XML: missing tag start", @source)
end
tag = md[1]
@document_status = :in_element
prefixes = Set.new
prefixes << md[2] if md[2]
Expand All @@ -405,23 +406,20 @@ def pull_event
end

if closed
@closed = md[1]
@closed = tag
@nsstack.shift
else
@tags.push( md[1] )
@tags.push( tag )
end
return [ :start_element, md[1], attributes ]
return [ :start_element, tag, attributes ]
end
else
md = @source.match( TEXT_PATTERN, true )
text = md[1]
if md[0].length == 0
@source.match( /(\s+)/, true )
end
#STDERR.puts "GOT #{md[1].inspect}" unless md[0].length == 0
#return [ :text, "" ] if md[0].length == 0
# unnormalized = Text::unnormalize( md[1], self )
# return PullEvent.new( :text, md[1], unnormalized )
return [ :text, md[1] ]
return [ :text, text ]
end
rescue REXML::UndefinedNamespaceException
raise
Expand Down
5 changes: 3 additions & 2 deletions lib/rexml/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Source
# value, overriding all encoding detection
def initialize(arg, encoding=nil)
@orig = @buffer = arg
@scanner = StringScanner.new(@buffer)
if encoding
self.encoding = encoding
else
Expand All @@ -62,7 +63,7 @@ def read
end

def match(pattern, cons=false)
@scanner = StringScanner.new(@buffer)
@scanner.string = @buffer
@scanner.scan(pattern)
@buffer = @scanner.rest if cons and @scanner.matched?

Expand Down Expand Up @@ -151,7 +152,7 @@ def read
end

def match( pattern, cons=false )
@scanner = StringScanner.new(@buffer)
@scanner.string = @buffer
@scanner.scan(pattern)
@buffer = @scanner.rest if cons and @scanner.matched?
while !@scanner.matched? and @source
Expand Down

0 comments on commit c87e1ab

Please sign in to comment.