new(arg, block_size=500, encoding=nil)
public
block_size has been deprecated
Show source
def initialize(arg, block_size=500, encoding=nil)
@er_source = @source = arg
@to_utf = false
@buffer = ""
str = @source.read( 2 ) || ''
if encoding
self.encoding = encoding
elsif str[0,2] == "\xfe\xff"
@line_break = "\0000>"
elsif str[0,2] == "\xff\xfe"
@line_break = ">\0000"
elsif str[0,2] == "\xef\xbb"
str += @source.read(1)
str = '' if (str[2,1] == "\xBF")
@line_break = ">"
else
@line_break = ">"
end
super( @source.eof? ? str : str+@source.readline( @line_break ) )
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