Class: REXML::IOSource
Overview
A Source that wraps an IO. See the Source class for method documentation
Constant Summary
Constants included
from Encoding
Encoding::UNILE, Encoding::UTF_16, Encoding::UTF_8
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
apply, #check_encoding, #decode_ascii, #decode_iconv, #decode_unile, #decode_utf8, #encode_ascii, #encode_iconv, #encode_unile, #encode_utf8, encoding_method, register
Constructor Details
#initialize(arg, block_size = 500, encoding = nil) ⇒ IOSource
block_size has been deprecated
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/rexml/source.rb', line 134
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 /\A(?:\xfe\xff|\xff\xfe)/n =~ str
self.encoding = check_encoding( str )
else
@line_break = '>'
end
super str+@source.readline( @line_break )
end
|
Instance Method Details
#consume(pattern) ⇒ Object
193
194
195
|
# File 'lib/rexml/source.rb', line 193
def consume( pattern )
match( pattern, true )
end
|
#current_line ⇒ Object
Returns the current line in the source.
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/rexml/source.rb', line 224
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
215
216
217
|
# File 'lib/rexml/source.rb', line 215
def empty?
super and ( @source.nil? || @source.eof? )
end
|
#match(pattern, cons = false) ⇒ Object
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/rexml/source.rb', line 197
def match( pattern, cons=false )
rv = pattern.match(@buffer)
@buffer = $' if cons and rv
while !rv and @source
begin
str = @source.readline(@line_break)
str = decode(str) if @to_utf and str
@buffer << str
rv = pattern.match(@buffer)
@buffer = $' if cons and rv
rescue
@source = nil
end
end
rv.taint
rv
end
|
219
220
221
|
# File 'lib/rexml/source.rb', line 219
def position
@er_source.stat.pipe? ? 0 : @er_source.pos
end
|
183
184
185
186
187
188
189
190
191
|
# File 'lib/rexml/source.rb', line 183
def read
begin
str = @source.readline(@line_break)
str = decode(str) if @to_utf and str
@buffer << str
rescue Exception, NameError
@source = nil
end
end
|
#scan(pattern, cons = false) ⇒ Object
156
157
158
159
160
161
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 156
def scan(pattern, cons=false)
rv = super
if rv.size == 0
until @buffer =~ pattern or @source.nil?
begin
str = @source.readline(@line_break)
str = decode(str) if @to_utf and str
@buffer << str
rescue Iconv::IllegalSequence
raise
rescue
@source = nil
end
end
rv = super
end
rv.taint
rv
end
|