class REXML::Source
A Source
can be searched for patterns, and wraps buffers and other objects and provides consumption of text
Attributes
The line number of the last consumed text
Public Class Methods
Source
# File lib/rexml/source.rb, line 87 def initialize(arg, encoding=nil) @orig = arg @scanner = StringScanner.new(@orig) if encoding self.encoding = encoding else detect_encoding end @line = 0 @encoded_terms = {} end
Constructor @param arg must be a String, and should be a valid XML document @param encoding if non-null, sets the encoding of the source to this value, overriding all encoding detection
Public Instance Methods
Source
# File lib/rexml/source.rb, line 100 def buffer @scanner.rest end
The current buffer (what we’re going to read next)
Source
# File lib/rexml/source.rb, line 110 def buffer_encoding=(encoding) @scanner.string.force_encoding(encoding) end
Source
# File lib/rexml/source.rb, line 175 def current_line lines = @orig.split res = lines.grep @scanner.rest[0..30] res = res[-1] if res.kind_of? Array lines.index( res ) if res end
@return the current line in the source
Source
# File lib/rexml/source.rb, line 104 def drop_parsed_content if @scanner.pos > Private::SCANNER_RESET_SIZE @scanner.string = @scanner.rest end end
Source
# File lib/rexml/source.rb, line 170 def empty? @scanner.eos? end
@return true if the Source
is exhausted
Source
# File lib/rexml/source.rb, line 116 def encoding=(enc) return unless super encoding_updated end
Inherited from Encoding
Overridden to support optimized en/decoding
Calls superclass method
REXML::Encoding#encoding=
Source
# File lib/rexml/source.rb, line 137 def match(pattern, cons=false) if cons @scanner.scan(pattern).nil? ? nil : @scanner else @scanner.check(pattern).nil? ? nil : @scanner end end
Source
# File lib/rexml/source.rb, line 145 def match?(pattern, cons=false) if cons !@scanner.skip(pattern).nil? else !@scanner.match?(pattern).nil? end end
Source
# File lib/rexml/source.rb, line 157 def position=(pos) @scanner.pos = pos end
Source
# File lib/rexml/source.rb, line 124 def read_until(term) pattern = Private::PRE_DEFINED_TERM_PATTERNS[term] || /#{Regexp.escape(term)}/ data = @scanner.scan_until(pattern) unless data data = @scanner.rest @scanner.pos = @scanner.string.bytesize end data end