A Source can be searched for patterns, and wraps buffers and other objects and provides consumption of text
Attributes
Name | Visibility | R/W | Description |
---|---|---|---|
buffer | public | R | The current buffer (what we‘re going to read next) |
encoding | public | R | |
line | public | R | The line number of the last consumed text |
Methods
Class
Visibility | Signature |
---|---|
public | new (arg, encoding=nil) |
Instance
Visibility | Signature |
---|---|
public | consume ( pattern ) |
public | current_line () |
public | empty? () |
public | encoding= (enc) |
public | match (pattern, cons=false) |
public | match_to ( char, pattern ) |
public | match_to_consume ( char, pattern ) |
public | position () |
public | read () |
public | scan (pattern, cons=false) |
Class Method Detail
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
Instance Method Detail
consume( pattern )
current_line()
@return the current line in the source
empty?()
@return true if the Source is exhausted
encoding=(enc)
Inherited from Encoding Overridden to support optimized en/decoding
match(pattern, cons=false)
match_to( char, pattern )
match_to_consume( char, pattern )
position()
read()
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 regexes 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.