In: |
rexml/source.rb
|
Parent: | Source |
attr_reader :block_size
# File rexml/source.rb, line 116 def initialize(arg, block_size=500) @er_source = @source = arg @to_utf = false # READLINE OPT # The following was commented out when IOSource started using readline # to pull the data from the stream. #@block_size = block_size #super @source.read(@block_size) @line_break = '>' #super @source.readline( "\n" ) super @source.readline( @line_break )+@source.read @line_break = encode( '>' ) end
# File rexml/source.rb, line 130 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 warrent duplicating # some code if rv.size == 0 until @buffer =~ pattern or @source.nil? begin # READLINE OPT #str = @source.read(@block_size) str = @source.readline(@line_break) str = decode(str) if @to_utf and str @buffer << str rescue @source = nil end end rv = super end rv.taint rv end
# File rexml/source.rb, line 155 def read begin str = @source.readline('>') str = decode(str) if @to_utf and str @buffer << str rescue Exception, NameError @source = nil end end
# File rexml/source.rb, line 169 def match( pattern, cons=false ) rv = pattern.match(@buffer) @buffer = $' if cons and rv while !rv and @source begin str = @source.readline('>') str = decode(str) if @to_utf and str @buffer << str rv = pattern.match(@buffer) @buffer = $' if cons and rv rescue @source = nil end end rv.taint rv end
@return the current line in the source
# File rexml/source.rb, line 192 def current_line pos = @er_source.pos # The byte position in the source lineno = @er_source.lineno # The XML < position in the source @er_source.rewind line = 0 # The \r\n position in the source begin while @er_source.pos < pos @er_source.readline line += 1 end rescue end [pos, lineno, line] end