diff options
author | ser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-19 02:58:11 +0000 |
---|---|---|
committer | ser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-19 02:58:11 +0000 |
commit | 21e8df5c109e4dd4f50bcebdebf8e4c4ce297560 (patch) | |
tree | bc15a6fc484d3df5ebe316d69359fa2d68cf6a5f /lib/rexml/functions.rb | |
parent | a399253153b1c4e6f09d798973524fa3dc158247 (diff) | |
download | ruby-21e8df5c109e4dd4f50bcebdebf8e4c4ce297560.tar.gz |
Merged in development from the main REXML repository.
* Fixed bug #34, typo in xpath_parser.
* Previous fix, (include? -> includes?) was incorrect.
* Added another test for encoding
* Started AnyName support in RelaxNG
* Added Element#Attributes#to_a, so that it does something intelligent.
This was needed by XPath, for '@*'
* Fixed XPath so that @* works.
* Added xmlgrep to the bin/ directory. A little tool allowing you to grep
for XPaths in an XML document.
* Fixed a CDATA pretty-printing bug. (#39)
* Fixed a buffering bug in Source.rb that affected the SAX parser
This bug was related to how REXML determines the encoding of a file, and
evinced itself by hanging on input when using the SAX parser.
* The unit test for the previous patch. Forgot to commit it.
* Minor pretty printing fix.
* Applied Curt Sampson's optimization improvements
* Issue #9; 3.1.3: The SAX parser was not denormalizing entity references
in incoming text. All declared internal entities, as well as numeric
entities, should now be denormalized. There was a related bug in that the
SAX parser was actually double-encoding entities; this is also fixed.
* bin/* programs should now be executable. Setting bin apps to executable
* Issue 14; 3.1.3: DTD events are now all being passed by StreamParser
Some of the DTD events were not being passed through by the stream parser.
* #26: Element#add_element(nil) now raises an error Changed XPath searches so
that if a non-Hash is passed, an error is raised Fixed a spurrious undefined
method error in encoding. #29: XPath ordering bug fixed by Mark Williams.
Incidentally, Mark supplied a superlative bug report, including a full unit
test. Then he went ahead and fixed the bug. It doesn't get any better than
this, folks.
* Fixed a broken link. Thanks to Dick Davies for pointing it out. Added
functions courtesy of Michael Neumann <mneumann@xxxx.de>.
Example code to follow.
* Added Michael's sample code. Merged the changes in from branches/xpath_V
* Fixed preceding:: and following:: axis Fixed the ordering bug that Martin
Fowler reported.
* Uncommented some code commented for testing Applied Nobu's changes to the
Encoding infrastructure, which should fix potential threading issues.
* Added more tests, and the missing syncenumerator class. Fixed the
inheritance bug in the pull parser that James Britt found. Indentation
changes, and changed some exceptions to runtime
exceptions.
* Changes by Matz, mostly of indent -> indent_level, to avoid
function/variable naming conflicts
* Tabs -> spaces (whitespace)
Note the addition of syncenumerator.rb. This is a stopgap, until I can work on
the class enough to get it accepted as a replacement for the SyncEnumerator
that comes with the Generator class. My version is orders of magnitude faster
than the Generator SyncEnumerator, but is currently missing a couple of
features of the original. Eventually, I expect this class to migrate to
another part of the source tree.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8483 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/functions.rb')
-rw-r--r-- | lib/rexml/functions.rb | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb index 9cbff99537..7a2fb996a0 100644 --- a/lib/rexml/functions.rb +++ b/lib/rexml/functions.rb @@ -7,41 +7,33 @@ module REXML # Therefore, in XML, "local-name()" is identical (and actually becomes) # "local_name()" module Functions - @@node = nil - @@index = nil - @@size = nil - @@variables = {} + @@context = nil @@namespace_context = {} + @@variables = {} - def Functions::node=(value); @@node = value; end - def Functions::index=(value); @@index = value; end - def Functions::size=(value); @@size = value; end - def Functions::variables=(value); @@variables = value; end - def Functions::namespace_context=(value) - @@namespace_context = value - end - def Functions::node; @@node; end - def Functions::index; @@index; end - def Functions::size; @@size; end - def Functions::variables; @@variables; end - def Functions::namespace_context; @@namespace_context; end + def Functions::namespace_context=(x) ; @@namespace_context=x ; end + def Functions::variables=(x) ; @@variables=x ; end + def Functions::namespace_context ; @@namespace_context ; end + def Functions::variables ; @@variables ; end + + def Functions::context=(value); @@context = value; end def Functions::text( ) - if @@node.node_type == :element - return @@node.text - elsif @@node.node_type == :text - return @@node.value + if @@context[:node].node_type == :element + return @@context[:node].find_all{|n| n.node_type == :text}.collect{|n| n.value} + elsif @@context[:node].node_type == :text + return @@context[:node].value else return false end end def Functions::last( ) - @@size + @@context[:size] end def Functions::position( ) - @@index + @@context[:index] end def Functions::count( node_set ) @@ -73,7 +65,7 @@ module REXML # Helper method. def Functions::get_namespace( node_set = nil ) if node_set == nil - yield @@node if defined? @@node.namespace + yield @@context[:node] if defined? @@context[:node].namespace else if node_set.namespace yield node_set @@ -214,7 +206,7 @@ module REXML # UNTESTED def Functions::normalize_space( string=nil ) - string = string(@@node) if string.nil? + string = string(@@context[:node]) if string.nil? if string.kind_of? Array string.collect{|x| string.to_s.strip.gsub(/\s+/um, ' ') if string} else @@ -291,7 +283,7 @@ module REXML # UNTESTED def Functions::lang( language ) lang = false - node = @@node + node = @@context[:node] attr = nil until node.nil? if node.node_type == :element @@ -325,15 +317,16 @@ module REXML # an object of a type other than the four basic types is converted to a # number in a way that is dependent on that type def Functions::number( object=nil ) - object = @@node unless object - if object == true + object = @@context[:node] unless object + case object + when true Float(1) - elsif object == false + when false Float(0) - elsif object.kind_of? Array + when Array number(string( object )) - elsif object.kind_of? Float - object + when Numeric + object.to_f else str = string( object ) #puts "STRING OF #{object.inspect} = #{str}" @@ -364,9 +357,13 @@ module REXML end end + def Functions::processing_instruction( node ) + node.node_type == :processing_instruction + end + def Functions::method_missing( id ) puts "METHOD MISSING #{id.id2name}" - XPath.match( @@node, id.id2name ) + XPath.match( @@context[:node], id.id2name ) end end end |