Class REXML::IOSource
In:
Parent: Source

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

Methods

consume   current_line   empty?   match   new   position   read   scan  

Public Class methods

block_size has been deprecated

[Source]

120:                 def initialize(arg, block_size=500)
121:                         @er_source = @source = arg
122:                         @to_utf = false
123:       # Determining the encoding is a deceptively difficult issue to resolve.
124:       # First, we check the first two bytes for UTF-16.  Then we
125:       # assume that the encoding is at least ASCII enough for the '>', and
126:       # we read until we get one of those.  This gives us the XML declaration,
127:       # if there is one.  If there isn't one, the file MUST be UTF-8, as per
128:       # the XML spec.  If there is one, we can determine the encoding from
129:       # it.
130:       str = @source.read( 2 )
131:       if (str[0] == 254 && str[1] == 255) || (str[0] == 255 && str[1] == 254)
132:         @encoding = check_encoding( str )
133:         @line_break = encode( '>' )
134:       else
135:         @line_break = '>'
136:       end
137:       super str+@source.readline( @line_break )
138:                 end

Public Instance methods

[Source]

175:                 def consume( pattern )
176:                         match( pattern, true )
177:                 end

@return the current line in the source

[Source]

206:                 def current_line
207:       begin
208:         pos = @er_source.pos                            # The byte position in the source
209:         lineno = @er_source.lineno      # The XML < position in the source
210:         @er_source.rewind
211:         line = 0                                                                                # The \r\n position in the source
212:         begin
213:           while @er_source.pos < pos
214:             @er_source.readline
215:             line += 1
216:           end
217:         rescue
218:         end
219:       rescue IOError
220:         pos = -1
221:         line = -1
222:       end
223:                         [pos, lineno, line]
224:                 end

[Source]

197:                 def empty?
198:                         super and ( @source.nil? || @source.eof? )
199:                 end

[Source]

179:                 def match( pattern, cons=false )
180:                         rv = pattern.match(@buffer)
181:                         @buffer = $' if cons and rv
182:                         while !rv and @source
183:                                 begin
184:           str = @source.readline(@line_break)
185:                                         str = decode(str) if @to_utf and str
186:                                         @buffer << str
187:                                         rv = pattern.match(@buffer)
188:                                         @buffer = $' if cons and rv
189:                                 rescue
190:                                         @source = nil
191:                                 end
192:                         end
193:                         rv.taint
194:                         rv
195:                 end

[Source]

201:     def position
202:       @er_source.pos
203:     end

[Source]

165:                 def read
166:                         begin
167:         str = @source.readline(@line_break)
168:                                 str = decode(str) if @to_utf and str 
169:                                 @buffer << str
170:                         rescue Exception, NameError
171:                                 @source = nil
172:                         end
173:                 end

[Source]

140:                 def scan(pattern, cons=false)
141:                         rv = super
142:                         # You'll notice that this next section is very similar to the same
143:                         # section in match(), but just a liiittle different.  This is
144:                         # because it is a touch faster to do it this way with scan()
145:                         # than the way match() does it; enough faster to warrent duplicating
146:                         # some code
147:                         if rv.size == 0
148:                                 until @buffer =~ pattern or @source.nil?
149:                                         begin
150:                                                 # READLINE OPT
151:                                                 #str = @source.read(@block_size)
152:                                                 str = @source.readline(@line_break)
153:                                                 str = decode(str) if @to_utf and str
154:                                                 @buffer << str
155:                                         rescue
156:                                                 @source = nil
157:                                         end
158:                                 end
159:                                 rv = super
160:                         end
161:                         rv.taint
162:                         rv
163:                 end

Search

Google

Ruby API Docs

Links