A Source can be searched for patterns, and wraps buffers and other objects and provides consumption of text

Methods
C
E
M
N
P
R
S
Included Modules
Attributes
[R] buffer

The current buffer (what we're going to read next)

[R] encoding
[R] line

The line number of the last consumed text

Class Public methods
new(arg, encoding=nil)

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

# File lib/rexml/source.rb, line 42
def initialize(arg, encoding=nil)
  @orig = @buffer = arg
  if encoding
    self.encoding = encoding
  else
    detect_encoding
  end
  @line = 0
end
Instance Public methods
consume( pattern )
# File lib/rexml/source.rb, line 86
def consume( pattern )
  @buffer = $' if pattern.match( @buffer )
end
current_line()

@return the current line in the source

# File lib/rexml/source.rb, line 116
def current_line
  lines = @orig.split
  res = lines.grep @buffer[0..30]
  res = res[-1] if res.kind_of? Array
  lines.index( res ) if res
end
empty?()

@return true if the Source is exhausted

# File lib/rexml/source.rb, line 107
def empty?
  @buffer == ""
end
encoding=(enc)

Inherited from Encoding Overridden to support optimized en/decoding

# File lib/rexml/source.rb, line 55
def encoding=(enc)
  return unless super
  encoding_updated
end
match(pattern, cons=false)
# File lib/rexml/source.rb, line 100
def match(pattern, cons=false)
  md = pattern.match(@buffer)
  @buffer = $' if cons and md
  return md
end
match_to( char, pattern )
# File lib/rexml/source.rb, line 90
def match_to( char, pattern )
  return pattern.match(@buffer)
end
match_to_consume( char, pattern )
# File lib/rexml/source.rb, line 94
def match_to_consume( char, pattern )
  md = pattern.match(@buffer)
  @buffer = $'
  return md
end
position()
# File lib/rexml/source.rb, line 111
def position
  @orig.index( @buffer )
end
read()
# File lib/rexml/source.rb, line 83
def read
end
scan(pattern, cons=false)

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.

# File lib/rexml/source.rb, line 76
def scan(pattern, cons=false)
  return nil if @buffer.nil?
  rv = @buffer.scan(pattern)
  @buffer = $' if cons and rv.size>0
  rv
end