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

# File rexml/source.rb, line 138definitialize(arg, block_size=500, encoding=nil)
@er_source = @source = arg@to_utf = false# Determining the encoding is a deceptively difficult issue to resolve.# First, we check the first two bytes for UTF-16. Then we# assume that the encoding is at least ASCII enough for the '>', and# we read until we get one of those. This gives us the XML declaration,# if there is one. If there isn't one, the file MUST be UTF-8, as per# the XML spec. If there is one, we can determine the encoding from# it.@buffer = ""str = @source.read( 2 ) ||''ifencodingself.encoding = encodingelsifstr[0,2] =="\xfe\xff"@line_break = "\000>"elsifstr[0,2] =="\xff\xfe"@line_break = ">\000"elsifstr[0,2] =="\xef\xbb"str+=@source.read(1)
str = ''if (str[2,1] =="\xBF")
@line_break = ">"else@line_break = ">"endsuper( @source.eof??str:str+@source.readline( @line_break ) )
if!@to_utfand@buffer.respond_to?(:force_encoding) and@source.respond_to?(:external_encoding) and@source.external_encoding!=::Encoding::UTF_8@force_utf8 = trueelse@force_utf8 = falseendend

Public Instance Methods

# File rexml/source.rb, line 236defcurrent_linebeginpos = @er_source.pos# The byte position in the sourcelineno = @er_source.lineno# The XML < position in the source@er_source.rewindline = 0# The \r\n position in the sourcebeginwhile@er_source.pos<pos@er_source.readlineline+=1endrescueendrescueIOErrorpos = -1line = -1end
[pos, lineno, line]
end

# File rexml/source.rb, line 176defscan(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 codeifrv.size==0until@buffer=~patternor@source.nil?begin@buffer<<readlinerescueIconv::IllegalSequenceraiserescue@source = nilendendrv = superendrv.taintrvend

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.