summaryrefslogtreecommitdiff
path: root/lib/rexml/source.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rexml/source.rb')
-rw-r--r--lib/rexml/source.rb27
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb
index 7251666160..cacab221db 100644
--- a/lib/rexml/source.rb
+++ b/lib/rexml/source.rb
@@ -7,12 +7,19 @@ module REXML
# @param arg Either a String, or an IO
# @return a Source, or nil if a bad argument was given
def SourceFactory::create_from arg#, slurp=true
- if arg.kind_of? String
- source = Source.new(arg)
- elsif arg.kind_of? IO
- source = IOSource.new(arg)
- end
- source
+ if arg.kind_of? String
+ Source.new(arg)
+ elsif arg.respond_to? :read and
+ arg.respond_to? :readline and
+ arg.respond_to? :nil? and
+ arg.respond_to? :eof?
+ IOSource.new(arg)
+ elsif arg.kind_of? Source
+ arg
+ else
+ raise "#{source.class} is not a valid input stream. It must walk \n"+
+ "like either a String, IO, or Source."
+ end
end
end
@@ -98,6 +105,10 @@ module REXML
@buffer == ""
end
+ def position
+ @orig.index( @buffer )
+ end
+
# @return the current line in the source
def current_line
lines = @orig.split
@@ -194,6 +205,10 @@ module REXML
super and ( @source.nil? || @source.eof? )
end
+ def position
+ @er_source.stat.pipe? ? 0 : @er_source.pos
+ end
+
# @return the current line in the source
def current_line
begin