summaryrefslogtreecommitdiff
path: root/lib/rexml
diff options
context:
space:
mode:
authorser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-30 16:35:45 +0000
committerser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-30 16:35:45 +0000
commitf8d68a248260e721bf756a17fcac6bf1e218e66f (patch)
tree38e048a85c10ebbe2b7cb84a61ae570ca26ba30a /lib/rexml
parent2ffedb5f291d8d420ff3a197bba62bd3b329a1db (diff)
All of the tickets and issues mentioned in this log can be found at:
http://www.germane-software.com/projects/rexml/ticket/# where '#' is the issue or ticket number. * Fixes ticket:3 (Issue38 in Roundup.) However, this needs further testing. * Fixed a couple of bugs in the SAX2 parser, plus a bunch of other changes I don't remember. * More XPath ordering testing added * Fixed the documentation WRT the raw mode of text nodes (ticket:4) * Fixes roundup issue 43: substring-after bug. See: http://www.germane-software.com/cgi-bin/roundup/rexml/issue43 * Fixed issue44, Element#xpath * Patch submitted by an anonymous doner to allow parsing of Tempfiles. I was hoping that, by now, that whole Source thing would have been changed to use duck typing and avoid this sort of issue... but in the meantime, the patch has been applied. * Fixes ticket:30, XPath default namespace bug. The fix was provided by Lucas Nussbaum. * Aliases #size to #length, as per zdennis's request. * Fixes typo from previous commit * Fixes ticket #32 (and adds a unit test) * Merges a user-contributed patch for issue #40 * Changes Date, Version, and Copyright to upper case, to avoid conflicts with the Date class. * Minor, yet incomplete, documentation changes. * Resolves issue #34 (SAX parser change makes it impossible to parse IO feeds.) * Moves parser.source.position() to parser.position() * Improves the build script (less work for me to package a distribution) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml')
-rw-r--r--lib/rexml/element.rb2
-rw-r--r--lib/rexml/functions.rb9
-rw-r--r--lib/rexml/parent.rb17
-rw-r--r--lib/rexml/parsers/baseparser.rb11
-rw-r--r--lib/rexml/parsers/pullparser.rb1
-rw-r--r--lib/rexml/parsers/sax2parser.rb2
-rw-r--r--lib/rexml/rexml.rb10
-rw-r--r--lib/rexml/source.rb9
-rw-r--r--lib/rexml/text.rb10
-rw-r--r--lib/rexml/xpath_parser.rb7
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 ) #-> "&lt;&amp;"
- # Text.new( "<&", false, nil, true ) #-> IllegalArgumentException
+ # Text.new( "<&", false, nil, true ) #-> Parse exception
# Text.new( "&lt;&amp;", false, nil, true ) #-> "&lt;&amp;"
# # 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