Class: REXML::IOSource
  
  
  
Overview
  
    
A Source that wraps an IO.  See the Source class for method documentation
   
 
  
  Instance Attribute Summary
  
  Attributes inherited from Source
  #buffer, #encoding, #line
  
  
  Attributes included from Encoding
  #encoding
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Methods inherited from Source
  #match_to, #match_to_consume
  
  
  
  
  
  
  
  
  Methods included from Encoding
  #decode, #encode
  Constructor Details
  
    
  
  
    #initialize(arg, block_size = 500, encoding = nil)  ⇒ IOSource 
  
  
  
  
    
block_size has been deprecated
   
 
  
  
    
      
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 
     | 
    
      # 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 Method Details
    
      
  
  
    #consume(pattern)  ⇒ Object 
  
  
  
  
    
      
214
215
216 
     | 
    
      # File 'lib/rexml/source.rb', line 214
def consume( pattern )
  match( pattern, true )
end 
     | 
  
 
    
      
  
  
    #current_line  ⇒ Object 
  
  
  
  
    
Returns the current line in the source.
   
 
  
    
      
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261 
     | 
    
      # File 'lib/rexml/source.rb', line 243
def current_line
  begin
    pos = @er_source.pos            lineno = @er_source.lineno      @er_source.rewind
    line = 0                        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
     | 
  
 
    
      
  
  
    #empty?  ⇒ Boolean 
  
  
  
  
    
      
234
235
236 
     | 
    
      # File 'lib/rexml/source.rb', line 234
def empty?
  super and ( @source.nil? || @source.eof? )
end 
     | 
  
 
    
      
  
  
    #match(pattern, cons = false)  ⇒ Object 
  
  
  
  
    
      
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232 
     | 
    
      # 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
     | 
  
 
    
      
  
  
    
      
238
239
240 
     | 
    
      # File 'lib/rexml/source.rb', line 238
def position
  @er_source.pos rescue 0
end 
     | 
  
 
    
      
  
  
    
      
206
207
208
209
210
211
212 
     | 
    
      # File 'lib/rexml/source.rb', line 206
def read
  begin
    @buffer << readline
  rescue Exception, NameError
    @source = nil
  end
end
     | 
  
 
    
      
  
  
    #scan(pattern, cons = false)  ⇒ Object 
  
  
  
  
    
      
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204 
     | 
    
      # File 'lib/rexml/source.rb', line 183
def scan(pattern, cons=false)
  rv = super
            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
     |