diff options
Diffstat (limited to 'lib/rexml')
-rw-r--r-- | lib/rexml/element.rb | 2 | ||||
-rw-r--r-- | lib/rexml/functions.rb | 9 | ||||
-rw-r--r-- | lib/rexml/parent.rb | 17 | ||||
-rw-r--r-- | lib/rexml/parsers/baseparser.rb | 11 | ||||
-rw-r--r-- | lib/rexml/parsers/pullparser.rb | 1 | ||||
-rw-r--r-- | lib/rexml/parsers/sax2parser.rb | 2 | ||||
-rw-r--r-- | lib/rexml/rexml.rb | 10 | ||||
-rw-r--r-- | lib/rexml/source.rb | 9 | ||||
-rw-r--r-- | lib/rexml/text.rb | 10 | ||||
-rw-r--r-- | lib/rexml/xpath_parser.rb | 7 |
10 files changed, 47 insertions, 31 deletions
diff --git a/lib/rexml/element.rb b/lib/rexml/element.rb index e7754da2c5..0b025da475 100644 --- a/lib/rexml/element.rb +++ b/lib/rexml/element.rb @@ -713,7 +713,7 @@ module REXML private def __to_xpath_helper node - rv = node.expanded_name + rv = node.expanded_name.clone if node.parent results = node.parent.find_all {|n| n.kind_of?(REXML::Element) and n.expanded_name == node.expanded_name diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb index 0db9b98a53..010926611e 100644 --- a/lib/rexml/functions.rb +++ b/lib/rexml/functions.rb @@ -157,12 +157,9 @@ module REXML # Kouhei fixed this too def Functions::substring_after( string, test ) ruby_string = string(string) - ruby_index = ruby_string.index(string(test)) - if ruby_index.nil? - "" - else - ruby_string[ ruby_index+1..-1 ] - end + test_string = string(test) + return $1 if ruby_string =~ /#{test}(.*)/ + "" end # Take equal portions of Mike Stok and Sean Russell; mix diff --git a/lib/rexml/parent.rb b/lib/rexml/parent.rb index 5c1ed97324..cc74a40666 100644 --- a/lib/rexml/parent.rb +++ b/lib/rexml/parent.rb @@ -31,9 +31,11 @@ module REXML end def delete( object ) - return unless @children.include? object - @children.delete object - object.parent = nil + found = false + @children.delete_if {|c| + c.equal?(object) and found = true + } + object.parent = nil if found end def each(&block) @@ -131,15 +133,16 @@ module REXML @children.size end + alias :length :size + # Replaces one child with another, making sure the nodelist is correct # @param to_replace the child to replace (must be a Child) # @param replacement the child to insert into the nodelist (must be a # Child) def replace_child( to_replace, replacement ) - ind = @children.index( to_replace ) - to_replace.parent = nil - @children[ind,0] = replacement - replacement.parent = self + @children.map! {|c| c.equal?( to_replace ) ? replacement : c } + to_replace.parent = nil + replacement.parent = self end # Deeply clones this object. This creates a complete duplicate of this diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb index cb33a64908..c898ba0b60 100644 --- a/lib/rexml/parsers/baseparser.rb +++ b/lib/rexml/parsers/baseparser.rb @@ -128,6 +128,8 @@ module REXML @source = source elsif defined? StringIO and source.kind_of? StringIO @source = IOSource.new(source) + elsif defined? Tempfile and source.kind_of? Tempfile + @source = IOSource.new(source) else raise "#{source.class} is not a valid input stream. It must be \n"+ "either a String, IO, StringIO or Source." @@ -139,6 +141,15 @@ module REXML @entities = [] end + def position + if @source.respond_to? :position + @source.position + else + # FIXME + 0 + end + end + # Returns true if there are no more events def empty? #puts "@source.empty? = #{@source.empty?}" diff --git a/lib/rexml/parsers/pullparser.rb b/lib/rexml/parsers/pullparser.rb index 09ac8948f6..36dc7160c3 100644 --- a/lib/rexml/parsers/pullparser.rb +++ b/lib/rexml/parsers/pullparser.rb @@ -32,6 +32,7 @@ module REXML def_delegators( :@parser, :has_next? ) def_delegators( :@parser, :entity ) def_delegators( :@parser, :empty? ) + def_delegators( :@parser, :source ) def initialize stream @entities = {} diff --git a/lib/rexml/parsers/sax2parser.rb b/lib/rexml/parsers/sax2parser.rb index f1b8246902..61a216cec1 100644 --- a/lib/rexml/parsers/sax2parser.rb +++ b/lib/rexml/parsers/sax2parser.rb @@ -167,7 +167,7 @@ module REXML :elementdecl, :cdata, :notationdecl, :xmldecl handle( *event ) end - handle( :progress, @parser.source.position ) + handle( :progress, @parser.position ) end end diff --git a/lib/rexml/rexml.rb b/lib/rexml/rexml.rb index 86690b8488..285d50cea5 100644 --- a/lib/rexml/rexml.rb +++ b/lib/rexml/rexml.rb @@ -10,8 +10,8 @@ # # Main page:: http://www.germane-software.com/software/rexml # Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom> -# Version:: 3.1.3 -# Date:: 2005/224 +# Version:: 3.1.3.1 +# Date:: 2005/364 # # This API documentation can be downloaded from the REXML home page, or can # be accessed online[http://www.germane-software.com/software/rexml_doc] @@ -20,7 +20,7 @@ # or can be accessed # online[http://www.germane-software.com/software/rexml/docs/tutorial.html] module REXML - Copyright = "Copyright © 2001, 2002, 2003, 2004 Sean Russell <ser@germane-software.com>" - Date = "2005/224" - Version = "3.1.3" + Copyright = "Copyright © 2001-2005 Sean Russell <ser@germane-software.com>" + Date = "2005/364" + Version = "3.1.3.1" end diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb index f599d2276c..ddade5de0e 100644 --- a/lib/rexml/source.rb +++ b/lib/rexml/source.rb @@ -8,11 +8,12 @@ module REXML # @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) + Source.new(arg) elsif arg.kind_of? IO - source = IOSource.new(arg) + IOSource.new(arg) + elsif arg.kind_of? Source + arg end - source end end @@ -199,7 +200,7 @@ module REXML end def position - @er_source.pos + @er_source.stat.pipe? ? 0 : @er_source.pos end # @return the current line in the source diff --git a/lib/rexml/text.rb b/lib/rexml/text.rb index 9a83121af8..5d200deac6 100644 --- a/lib/rexml/text.rb +++ b/lib/rexml/text.rb @@ -39,8 +39,10 @@ module REXML # text. If this value is nil (the default), then the raw value of the # parent will be used as the raw value for this node. If there is no raw # value for the parent, and no value is supplied, the default is false. + # Use this field if you have entities defined for some text, and you don't + # want REXML to escape that text in output. # Text.new( "<&", false, nil, false ) #-> "<&" - # Text.new( "<&", false, nil, true ) #-> IllegalArgumentException + # Text.new( "<&", false, nil, true ) #-> Parse exception # Text.new( "<&", false, nil, true ) #-> "<&" # # Assume that the entity "s" is defined to be "sean" # # and that the entity "r" is defined to be "russell" @@ -156,11 +158,11 @@ module REXML # # Assume that the entity "s" is defined to be "sean", and that the # # entity "r" is defined to be "russell" # t = Text.new( "< & sean russell", false, nil, false, ['s'] ) - # t.string #-> "< & sean russell" + # t.value #-> "< & sean russell" # t = Text.new( "< & &s; russell", false, nil, false ) - # t.string #-> "< & sean russell" + # t.value #-> "< & sean russell" # u = Text.new( "sean russell", false, nil, true ) - # u.string #-> "sean russell" + # u.value #-> "sean russell" def value @unnormalized if @unnormalized doctype = nil diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb index 7c0d1dc358..fbfe608746 100644 --- a/lib/rexml/xpath_parser.rb +++ b/lib/rexml/xpath_parser.rb @@ -152,9 +152,10 @@ module REXML #puts "IN QNAME" prefix = path_stack.shift name = path_stack.shift - ns = @namespaces[prefix] - ns = ns ? ns : '' + default_ns = @namespaces[prefix] + default_ns = default_ns ? default_ns : '' nodeset.delete_if do |node| + ns = default_ns # FIXME: This DOUBLES the time XPath searches take ns = node.namespace( prefix ) if node.node_type == :element and ns == '' #puts "NS = #{ns.inspect}" @@ -347,7 +348,7 @@ module REXML preceding_siblings = all_siblings[ 0 .. current_index-1 ].reverse #results += expr( path_stack.dclone, preceding_siblings ) end - nodeset = preceding_siblings + nodeset = preceding_siblings || [] node_types = ELEMENTS when :preceding |