class REXML::IOSource

A Source that wraps an IO. See the Source class for method documentation

Public Class Methods

new(arg, block_size=500, encoding=nil) click to toggle source

block_size has been deprecated

Calls superclass method REXML::Source::new
# File lib/rexml/source.rb, line 140
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
      @orig.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

Public Instance Methods

current_line() click to toggle source

@return the current line in the source

# File lib/rexml/source.rb, line 199
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
    @er_source.seek(pos)
  rescue IOError
    pos = -1
    line = -1
  end
  [pos, lineno, line]
end
empty?() click to toggle source
Calls superclass method REXML::Source#empty?
# File lib/rexml/source.rb, line 194
def empty?
  super and ( @source.nil? || @source.eof? )
end
ensure_buffer() click to toggle source
# File lib/rexml/source.rb, line 171
def ensure_buffer
  read if @scanner.eos? && @source
end
match( pattern, cons=false ) click to toggle source

Note: When specifying a string for 'pattern', it must not include '>' except in the following formats:

  • “>”

  • “XXX>” (X is any string excluding '>')

# File lib/rexml/source.rb, line 178
def match( pattern, cons=false )
  while true
    if cons
      md = @scanner.scan(pattern)
    else
      md = @scanner.check(pattern)
    end
    break if md
    return nil if pattern.is_a?(String)
    return nil if @source.nil?
    return nil unless read
  end

  md.nil? ? nil : @scanner
end
read() click to toggle source
# File lib/rexml/source.rb, line 161
def read
  begin
    @scanner << readline
    true
  rescue Exception, NameError
    @source = nil
    false
  end
end