Class: REXML::IOSource
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| Class Chain: 
          self,
          Source
         | |
| Instance Chain: | |
| Inherits: | REXML::Source 
 | 
| Defined in: | lib/rexml/source.rb | 
Overview
A Source that wraps an IO. See the Source class for method documentation
Class Method Summary
- 
    
      .new(arg, block_size = 500, encoding = nil)  ⇒ IOSource 
    
    constructor
    block_size has been deprecated. 
Source - Inherited
| .new | Constructor value, overriding all encoding detection. | 
Instance Attribute Summary
- #empty? ⇒ Boolean readonly
Source - Inherited
| #encoding, | |
| #encoding= | Inherited from Encoding Overridden to support optimized en/decoding. | 
| #buffer | The current buffer (what we're going to read next). | 
| #empty?, | |
| #line | The line number of the last consumed text. | 
Encoding - Included
| #encoding | ID —> Encoding name. | 
| #encoding= | |
Instance Method Summary
- #consume(pattern)
- #current_line ⇒ Object
- #match(pattern, cons = false)
- #position
- #read
- #scan(pattern, cons = false)
- #encoding_updated private
- #readline private
Source - Inherited
| #consume, #current_line, #match, #match_to, #match_to_consume, #position, #read, | |
| #scan | Scans the source for a given pattern. | 
| #detect_encoding, #encoding_updated | |
Encoding - Included
Constructor Details
    .new(arg, block_size = 500, encoding = nil)  ⇒ IOSource 
  
block_size has been deprecated
# File 'lib/rexml/source.rb', line 162
def initialize(arg, block_size=500, encoding=nil) @er_source = @source = arg @to_utf = false @pending_buffer = nil if encoding super("", encoding) else super(@source.read(3) || "") end if !@to_utf and @buffer.respond_to?(:force_encoding) and @source.respond_to?(:external_encoding) and @source.external_encoding != ::Encoding::UTF_8 @force_utf8 = true else @force_utf8 = false end end
Instance Attribute Details
    #empty?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rexml/source.rb', line 234
def empty? super and ( @source.nil? || @source.eof? ) end
Instance Method Details
#consume(pattern)
[ GitHub ]# File 'lib/rexml/source.rb', line 214
def consume( pattern ) match( pattern, true ) end
#current_line ⇒ Object
# File 'lib/rexml/source.rb', line 243
def current_line begin 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 rescue IOError pos = -1 line = -1 end [pos, lineno, line] end
#encoding_updated (private)
[ GitHub ]# File 'lib/rexml/source.rb', line 284
def encoding_updated case @encoding when "UTF-16BE", "UTF-16LE" @source.binmode @source.set_encoding(@encoding, @encoding) end @line_break = encode(">") @pending_buffer, @buffer = @buffer, "" @pending_buffer.force_encoding(@encoding) super end
#match(pattern, cons = false)
[ GitHub ]# File 'lib/rexml/source.rb', line 218
def match( pattern, cons=false ) rv = pattern.match(@buffer) @buffer = $' if cons and rv while !rv and @source begin @buffer << readline rv = pattern.match(@buffer) @buffer = $' if cons and rv rescue @source = nil end end rv.taint rv end
#position
[ GitHub ]# File 'lib/rexml/source.rb', line 238
def position @er_source.pos rescue 0 end
#read
[ GitHub ]# File 'lib/rexml/source.rb', line 206
def read begin @buffer << readline rescue Exception, NameError @source = nil end end
#readline (private)
[ GitHub ]# File 'lib/rexml/source.rb', line 264
def readline str = @source.readline(@line_break) if @pending_buffer if str.nil? str = @pending_buffer else str = @pending_buffer + str end @pending_buffer = nil end return nil if str.nil? if @to_utf decode(str) else str.force_encoding(::Encoding::UTF_8) if @force_utf8 str end end
#scan(pattern, cons = false)
[ GitHub ]# File 'lib/rexml/source.rb', line 183
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 @buffer << readline rescue Iconv::IllegalSequence raise rescue @source = nil end end rv = super end rv.taint rv end