From 287a34ae0dfc23e4158f67cb7783d239f202c368 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 6 Mar 2009 03:56:38 +0000 Subject: * {ext,lib,test}/**/*.rb: removed trailing spaces. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rexml/attlistdecl.rb | 2 +- lib/rexml/attribute.rb | 16 ++--- lib/rexml/cdata.rb | 2 +- lib/rexml/child.rb | 6 +- lib/rexml/comment.rb | 6 +- lib/rexml/doctype.rb | 34 ++++----- lib/rexml/document.rb | 14 ++-- lib/rexml/dtd/entitydecl.rb | 2 +- lib/rexml/dtd/notationdecl.rb | 2 +- lib/rexml/element.rb | 140 ++++++++++++++++++------------------- lib/rexml/encoding.rb | 2 +- lib/rexml/encodings/CP-1252.rb | 2 +- lib/rexml/encodings/ISO-8859-15.rb | 2 +- lib/rexml/encodings/UNILE.rb | 2 +- lib/rexml/encodings/UTF-16.rb | 2 +- lib/rexml/entity.rb | 4 +- lib/rexml/formatters/default.rb | 4 +- lib/rexml/formatters/pretty.rb | 2 +- lib/rexml/formatters/transitive.rb | 2 +- lib/rexml/functions.rb | 34 ++++----- lib/rexml/instruction.rb | 4 +- lib/rexml/namespace.rb | 2 +- lib/rexml/node.rb | 2 +- lib/rexml/output.rb | 2 +- lib/rexml/parent.rb | 50 ++++++------- lib/rexml/parseexception.rb | 6 +- lib/rexml/parsers/baseparser.rb | 30 ++++---- lib/rexml/parsers/pullparser.rb | 2 +- lib/rexml/parsers/sax2parser.rb | 32 ++++----- lib/rexml/parsers/streamparser.rb | 4 +- lib/rexml/parsers/treeparser.rb | 4 +- lib/rexml/parsers/xpathparser.rb | 20 +++--- lib/rexml/quickpath.rb | 16 ++--- lib/rexml/rexml.rb | 8 +-- lib/rexml/sax2listener.rb | 8 +-- lib/rexml/source.rb | 10 +-- lib/rexml/streamlistener.rb | 6 +- lib/rexml/text.rb | 44 ++++++------ lib/rexml/validation/relaxng.rb | 34 ++++----- lib/rexml/validation/validation.rb | 6 +- lib/rexml/xpath.rb | 2 +- lib/rexml/xpath_parser.rb | 42 +++++------ 42 files changed, 307 insertions(+), 307 deletions(-) (limited to 'lib/rexml') diff --git a/lib/rexml/attlistdecl.rb b/lib/rexml/attlistdecl.rb index ea5a98b69e..ec4e6c3b8d 100644 --- a/lib/rexml/attlistdecl.rb +++ b/lib/rexml/attlistdecl.rb @@ -31,7 +31,7 @@ module REXML @element_name, @pairs, @contents = *source end end - + # Access the attlist attribute/value pairs. # value = attlist_decl[ attribute_name ] def [](key) diff --git a/lib/rexml/attribute.rb b/lib/rexml/attribute.rb index febcc288b1..28a5923608 100644 --- a/lib/rexml/attribute.rb +++ b/lib/rexml/attribute.rb @@ -14,7 +14,7 @@ module REXML attr_reader :element # The normalized value of this attribute. That is, the attribute with # entities intact. - attr_writer :normalized + attr_writer :normalized PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um NEEDS_A_SECOND_CHECK = /(<|&((#{Entity::NAME});|(#0*((?:\d+)|(?:x[a-fA-F0-9]+)));)?)/um @@ -22,18 +22,18 @@ module REXML # Constructor. # FIXME: The parser doesn't catch illegal characters in attributes # - # first:: + # first:: # Either: an Attribute, which this new attribute will become a # clone of; or a String, which is the name of this attribute # second:: # If +first+ is an Attribute, then this may be an Element, or nil. # If nil, then the Element parent of this attribute is the parent - # of the +first+ Attribute. If the first argument is a String, - # then this must also be a String, and is the content of the attribute. + # of the +first+ Attribute. If the first argument is a String, + # then this must also be a String, and is the content of the attribute. # If this is the content, it must be fully normalized (contain no # illegal characters). # parent:: - # Ignored unless +first+ is a String; otherwise, may be the Element + # Ignored unless +first+ is a String; otherwise, may be the Element # parent of this attribute, or nil. # # @@ -61,7 +61,7 @@ module REXML end # Returns the namespace of the attribute. - # + # # e = Element.new( "elns:myelement" ) # e.add_attribute( "nsa:a", "aval" ) # e.add_attribute( "b", "bval" ) @@ -78,7 +78,7 @@ module REXML end # Returns the namespace URL, if defined, or nil otherwise - # + # # e = Element.new("el") # e.add_attributes({"xmlns:ns", "http://url"}) # e.namespace( "ns" ) # -> "http://url" @@ -157,7 +157,7 @@ module REXML end # Removes this Attribute from the tree, and returns true if successfull - # + # # This method is usually not called directly. def remove @element.attributes.delete self.name unless @element.nil? diff --git a/lib/rexml/cdata.rb b/lib/rexml/cdata.rb index 123a7c3d82..e1235d60f8 100644 --- a/lib/rexml/cdata.rb +++ b/lib/rexml/cdata.rb @@ -17,7 +17,7 @@ module REXML end # Make a copy of this object - # + # # _Examples_ # c = CData.new( "Some text" ) # d = c.clone diff --git a/lib/rexml/child.rb b/lib/rexml/child.rb index 033057da55..fd59d7283a 100644 --- a/lib/rexml/child.rb +++ b/lib/rexml/child.rb @@ -15,8 +15,8 @@ module REXML # if supplied, the parent of this child will be set to the # supplied value, and self will be added to the parent def initialize( parent = nil ) - @parent = nil - # Declare @parent, but don't define it. The next line sets the + @parent = nil + # Declare @parent, but don't define it. The next line sets the # parent. parent.add( self ) if parent end @@ -68,7 +68,7 @@ module REXML parent.insert_after self, other end - # Sets the previous sibling of this child. This can be used to insert a + # Sets the previous sibling of this child. This can be used to insert a # child before some other child. # a = Element.new("a") # b = a.add_element("b") diff --git a/lib/rexml/comment.rb b/lib/rexml/comment.rb index d5be89b652..e401090376 100644 --- a/lib/rexml/comment.rb +++ b/lib/rexml/comment.rb @@ -14,11 +14,11 @@ module REXML ## # Constructor. The first argument can be one of three types: - # @param first If String, the contents of this comment are set to the + # @param first If String, the contents of this comment are set to the # argument. If Comment, the argument is duplicated. If # Source, the argument is scanned for a comment. - # @param second If the first argument is a Source, this argument - # should be nil, not supplied, or a Parent to be set as the parent + # @param second If the first argument is a Source, this argument + # should be nil, not supplied, or a Parent to be set as the parent # of this object def initialize( first, second = nil ) #puts "IN COMMENT CONSTRUCTOR; SECOND IS #{second.type}" diff --git a/lib/rexml/doctype.rb b/lib/rexml/doctype.rb index 35beabc566..1a946a1587 100644 --- a/lib/rexml/doctype.rb +++ b/lib/rexml/doctype.rb @@ -15,11 +15,11 @@ module REXML STOP = ">" SYSTEM = "SYSTEM" PUBLIC = "PUBLIC" - DEFAULT_ENTITIES = { - 'gt'=>EntityConst::GT, - 'lt'=>EntityConst::LT, - 'quot'=>EntityConst::QUOT, - "apos"=>EntityConst::APOS + DEFAULT_ENTITIES = { + 'gt'=>EntityConst::GT, + 'lt'=>EntityConst::LT, + 'quot'=>EntityConst::QUOT, + "apos"=>EntityConst::APOS } # name is the name of the doctype @@ -33,7 +33,7 @@ module REXML # dt = DocType.new( doctype_to_clone ) # # Incomplete. Shallow clone of doctype # - # +Note+ that the constructor: + # +Note+ that the constructor: # # Doctype.new( Source.new( "" ) ) # @@ -139,8 +139,8 @@ module REXML @entities = DEFAULT_ENTITIES.clone if @entities == DEFAULT_ENTITIES @entities[ child.name ] = child if child.kind_of? Entity end - - # This method retrieves the public identifier identifying the document's + + # This method retrieves the public identifier identifying the document's # DTD. # # Method contributed by Henrik Martensson @@ -152,7 +152,7 @@ module REXML strip_quotes(@long_name) end end - + # This method retrieves the system identifier identifying the document's DTD # # Method contributed by Henrik Martensson @@ -164,16 +164,16 @@ module REXML @uri.kind_of?(String) ? strip_quotes(@uri) : nil end end - + # This method returns a list of notations that have been declared in the - # _internal_ DTD subset. Notations in the external DTD subset are not + # _internal_ DTD subset. Notations in the external DTD subset are not # listed. # # Method contributed by Henrik Martensson def notations children().select {|node| node.kind_of?(REXML::NotationDecl)} end - + # Retrieves a named notation. Only notations declared in the internal # DTD subset can be retrieved. # @@ -183,9 +183,9 @@ module REXML notation_decl.name == name } end - + private - + # Method contributed by Henrik Martensson def strip_quotes(quoted_string) quoted_string =~ /^[\'\"].*[\'\"]$/ ? @@ -217,7 +217,7 @@ module REXML output << to_s end end - + public class ElementDecl < Declaration def initialize( src ) @@ -250,7 +250,7 @@ module REXML def to_s "" @@ -259,7 +259,7 @@ module REXML def write( output, indent=-1 ) output << to_s end - + # This method retrieves the name of the notation. # # Method contributed by Henrik Martensson diff --git a/lib/rexml/document.rb b/lib/rexml/document.rb index 48f1a0ec6c..0fde6df1a1 100644 --- a/lib/rexml/document.rb +++ b/lib/rexml/document.rb @@ -25,7 +25,7 @@ module REXML DECLARATION = XMLDecl.default # Constructor - # @param source if supplied, must be a Document, String, or IO. + # @param source if supplied, must be a Document, String, or IO. # Documents have their context and Element attributes cloned. # Strings are expected to be valid XML documents. IOs are expected # to be sources of valid XML documents. @@ -69,11 +69,11 @@ module REXML @children.unshift child child.parent = self elsif child.kind_of? DocType - # Find first Element or DocType node and insert the decl right + # Find first Element or DocType node and insert the decl right # before it. If there is no such node, just insert the child at the # end. If there is a child and it is an DocType, then replace it. insert_before_index = 0 - @children.find { |x| + @children.find { |x| insert_before_index += 1 x.kind_of?(Element) || x.kind_of?(DocType) } @@ -167,7 +167,7 @@ module REXML # indent:: # An integer. If -1, no indenting will be used; otherwise, the # indentation will be twice this number of spaces, and children will be - # indented an additional amount. For a value of 3, every item will be + # indented an additional amount. For a value of 3, every item will be # indented 3 more levels, or 6 more spaces (2 * 3). Defaults to -1 # transitive:: # If transitive is true and indent is >= 0, then the output will be @@ -178,7 +178,7 @@ module REXML # Internet Explorer is the worst piece of crap to have ever been # written, with the possible exception of Windows itself. Since IE is # unable to parse proper XML, we have to provide a hack to generate XML - # that IE's limited abilities can handle. This hack inserts a space + # that IE's limited abilities can handle. This hack inserts a space # before the /> on empty tags. Defaults to false def write( output=$stdout, indent=-1, transitive=false, ie_hack=false ) if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output) @@ -197,7 +197,7 @@ module REXML formatter.write( self, output ) end - + def Document::parse_stream( source, listener ) Parsers::StreamParser.new( source, listener ).parse end @@ -215,7 +215,7 @@ module REXML end attr_reader :entity_expansion_count - + def record_entity_expansion @entity_expansion_count += 1 if @entity_expansion_count > @@entity_expansion_limit diff --git a/lib/rexml/dtd/entitydecl.rb b/lib/rexml/dtd/entitydecl.rb index 0adda6f7b9..a9286b2b90 100644 --- a/lib/rexml/dtd/entitydecl.rb +++ b/lib/rexml/dtd/entitydecl.rb @@ -49,7 +49,7 @@ module REXML def EntityDecl.parse_source source, listener md = source.match( PATTERN_RE, true ) thing = md[0].squeeze(" \t\n\r") - listener.send inspect.downcase, thing + listener.send inspect.downcase, thing end end end diff --git a/lib/rexml/dtd/notationdecl.rb b/lib/rexml/dtd/notationdecl.rb index eae71f2e52..17d1b9ef29 100644 --- a/lib/rexml/dtd/notationdecl.rb +++ b/lib/rexml/dtd/notationdecl.rb @@ -32,7 +32,7 @@ module REXML def NotationDecl.parse_source source, listener md = source.match( PATTERN_RE, true ) thing = md[0].squeeze(" \t\n\r") - listener.send inspect.downcase, thing + listener.send inspect.downcase, thing end end end diff --git a/lib/rexml/element.rb b/lib/rexml/element.rb index 92308a5c99..7a3abc65e5 100644 --- a/lib/rexml/element.rb +++ b/lib/rexml/element.rb @@ -30,13 +30,13 @@ module REXML attr_accessor :context # Constructor - # arg:: + # arg:: # if not supplied, will be set to the default value. # If a String, the name of this object will be set to the argument. - # If an Element, the object will be shallowly cloned; name, + # If an Element, the object will be shallowly cloned; name, # attributes, and namespaces will be copied. Children will +not+ be # copied. - # parent:: + # parent:: # if supplied, must be a Parent, and will be used as # the parent of this object. # context:: @@ -97,7 +97,7 @@ module REXML self.class.new self end - # Evaluates to the root node of the document that this element + # Evaluates to the root node of the document that this element # belongs to. If this element doesn't belong to a document, but does # belong to another Element, the parent's root will be returned, until the # earliest ancestor is found. @@ -137,8 +137,8 @@ module REXML # is the case if: # 1. Neither :+respect_whitespace+ nor :+compress_whitespace+ has any value # 2. The context has :+respect_whitespace+ set to :+all+ or - # an array containing the name of this element, and - # :+compress_whitespace+ isn't set to :+all+ or an array containing the + # an array containing the name of this element, and + # :+compress_whitespace+ isn't set to :+all+ or an array containing the # name of this element. # The evaluation is tested against +expanded_name+, and so is namespace # sensitive. @@ -162,7 +162,7 @@ module REXML @ignore_whitespace_nodes = false if @context if @context[:ignore_whitespace_nodes] - @ignore_whitespace_nodes = + @ignore_whitespace_nodes = (@context[:ignore_whitespace_nodes] == :all or @context[:ignore_whitespace_nodes].include? expanded_name) end @@ -206,13 +206,13 @@ module REXML return namespaces end - # Evalutas to the URI for a prefix, or the empty string if no such + # Evalutas to the URI for a prefix, or the empty string if no such # namespace is declared for this element. Evaluates recursively for # ancestors. Returns the default namespace, if there is one. - # prefix:: + # prefix:: # the prefix to search for. If not supplied, returns the default # namespace if one exists - # Returns:: + # Returns:: # the namespace URI as a String, or nil if no such namespace # exists. If the namespace is undefined, returns an empty string # doc = Document.new("") @@ -235,10 +235,10 @@ module REXML end # Adds a namespace to this element. - # prefix:: + # prefix:: # the prefix string, or the namespace URI if +uri+ is not # supplied - # uri:: + # uri:: # the namespace URI. May be nil, in which +prefix+ is used as # the URI # Evaluates to: this Element @@ -280,12 +280,12 @@ module REXML # Adds a child to this element, optionally setting attributes in # the element. - # element:: + # element:: # optional. If Element, the element is added. # Otherwise, a new Element is constructed with the argument (see # Element.initialize). - # attrs:: - # If supplied, must be a Hash containing String name,value + # attrs:: + # If supplied, must be a Hash containing String name,value # pairs, which will be used to set the attributes of the new Element. # Returns:: the Element that was added # el = doc.add_element 'my-tag' @@ -302,9 +302,9 @@ module REXML end # Deletes a child element. - # element:: - # Must be an +Element+, +String+, or +Integer+. If Element, - # the element is removed. If String, the element is found (via XPath) + # element:: + # Must be an +Element+, +String+, or +Integer+. If Element, + # the element is removed. If String, the element is found (via XPath) # and removed. This means that any parent can remove any # descendant. If Integer, the Element indexed by that number will be # removed. @@ -327,14 +327,14 @@ module REXML # Iterates through the child elements, yielding for each Element that # has a particular attribute set. - # key:: + # key:: # the name of the attribute to search for - # value:: + # value:: # the value of the attribute - # max:: - # (optional) causes this method to return after yielding + # max:: + # (optional) causes this method to return after yielding # for this number of matching children - # name:: + # name:: # (optional) if supplied, this is an XPath that filters # the children to check. # @@ -348,7 +348,7 @@ module REXML # # Yields d # doc.root.each_element_with_attribute( 'id', '1', 0, 'd' ) {|e| p e} def each_element_with_attribute( key, value=nil, max=0, name=nil, &block ) # :yields: Element - each_with_something( proc {|child| + each_with_something( proc {|child| if value.nil? child.attributes[key] != nil else @@ -359,13 +359,13 @@ module REXML # Iterates through the children, yielding for each Element that # has a particular text set. - # text:: + # text:: # the text to search for. If nil, or not supplied, will iterate # over all +Element+ children that contain at least one +Text+ node. - # max:: + # max:: # (optional) causes this method to return after yielding # for this number of matching children - # name:: + # name:: # (optional) if supplied, this is an XPath that filters # the children to check. # @@ -379,7 +379,7 @@ module REXML # # Yields d # doc.each_element_with_text(nil, 0, 'd'){|e|p e} def each_element_with_text( text=nil, max=0, name=nil, &block ) # :yields: Element - each_with_something( proc {|child| + each_with_something( proc {|child| if text.nil? child.has_text? else @@ -408,7 +408,7 @@ module REXML # doc.root.elements['c'].next_element #-> nil def next_element element = next_sibling - element = element.next_sibling until element.nil? or element.kind_of? Element + element = element.next_sibling until element.nil? or element.kind_of? Element return element end @@ -477,7 +477,7 @@ module REXML # this method with a nil argument. In this case, the next Text # child becomes the first Text child. In no case is the order of # any siblings disturbed. - # text:: + # text:: # If a String, a new Text child is created and added to # this Element as the first Text child. If Text, the text is set # as the first Child element. If nil, then any existing first Text @@ -520,7 +520,7 @@ module REXML # Note that at the end of this example, the branch has 3 nodes; the 'e' # element and 2 Text node children. def add_text( text ) - if text.kind_of? String + if text.kind_of? String if @children[-1].kind_of? Text @children[-1] << text return @@ -559,7 +559,7 @@ module REXML end prefix = nil if prefix == 'xmlns' - ret_val = + ret_val = attributes.get_attribute( "#{prefix ? prefix + ':' : ''}#{name}" ) return ret_val unless ret_val.nil? @@ -586,7 +586,7 @@ module REXML # the attribute is added to the list of Element attributes. If String, # the argument is used as the name of the new attribute, and the value # parameter must be supplied. - # value:: + # value:: # Required if +key+ is a String, and ignored if the first argument is # an Attribute. This is a String, and is used as the value # of the new Attribute. This should be the unnormalized value of the @@ -621,7 +621,7 @@ module REXML # either an Attribute or a String. In either case, the # attribute is found by matching the attribute name to the argument, # and then removed. If no attribute is found, no action is taken. - # Returns:: + # Returns:: # the attribute removed, or nil if this Element did not contain # a matching attribute # e = Element.new('E') @@ -638,7 +638,7 @@ module REXML # Other Utilities # ################################################# - # Get an array of all CData children. + # Get an array of all CData children. # IMMUTABLE def cdatas find_all { |child| child.kind_of? CData }.freeze @@ -681,7 +681,7 @@ module REXML # Internet Explorer is the worst piece of crap to have ever been # written, with the possible exception of Windows itself. Since IE is # unable to parse proper XML, we have to provide a hack to generate XML - # that IE's limited abilities can handle. This hack inserts a space + # that IE's limited abilities can handle. This hack inserts a space # before the /> on empty tags. Defaults to false # # out = '' @@ -707,8 +707,8 @@ module REXML def __to_xpath_helper node 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 + results = node.parent.find_all {|n| + n.kind_of?(REXML::Element) and n.expanded_name == node.expanded_name } if results.length > 1 idx = results.index( node ) @@ -734,7 +734,7 @@ module REXML # A class which provides filtering of children for Elements, and # XPath search support. You are expected to only encounter this class as - # the element.elements object. Therefore, you are + # the element.elements object. Therefore, you are # _not_ expected to instantiate this yourself. class Elements include Enumerable @@ -746,7 +746,7 @@ module REXML # Fetches a child element. Filters only Element children, regardless of # the XPath match. - # index:: + # index:: # the search parameter. This is either an Integer, which # will be used to find the index'th child Element, or an XPath, # which will be used to search for the Element. Because @@ -756,7 +756,7 @@ module REXML # child element is at index 1, not 0, and the +n+th element is at index # +n+, not n-1. This is because XPath indexes element children # starting from 1, not 0, and the indexes should be the same. - # name:: + # name:: # optional, and only used in the first argument is an # Integer. In that case, the index'th child Element that has the # supplied name will be returned. Note again that the indexes start at 1. @@ -772,12 +772,12 @@ module REXML num = 0 @element.find { |child| child.kind_of? Element and - (name.nil? ? true : child.has_name?( name )) and + (name.nil? ? true : child.has_name?( name )) and (num += 1) == index } else return XPath::first( @element, index ) - #{ |element| + #{ |element| # return element if element.kind_of? Element #} #return nil @@ -787,7 +787,7 @@ module REXML # Sets an element, replacing any previous matching element. If no # existing element is found ,the element is added. # index:: Used to find a matching element to replace. See [](). - # element:: + # element:: # The element to replace the existing element with # the previous element # Returns:: nil if no previous element was found. @@ -812,12 +812,12 @@ module REXML @element.find{ |child| child.kind_of? Element}.nil? end - # Returns the index of the supplied child (starting at 1), or -1 if + # Returns the index of the supplied child (starting at 1), or -1 if # the element is not a child # element:: an +Element+ child def index element rv = 0 - found = @element.find do |child| + found = @element.find do |child| child.kind_of? Element and (rv += 1) and child == element @@ -827,7 +827,7 @@ module REXML end # Deletes a child Element - # element:: + # element:: # Either an Element, which is removed directly; an # xpath, where the first matching child is removed; or an Integer, # where the n'th Element is removed. @@ -854,7 +854,7 @@ module REXML # deleted = doc.elements.delete_all 'a/c' #-> [, , , ] def delete_all( xpath ) rv = [] - XPath::each( @element, xpath) {|element| + XPath::each( @element, xpath) {|element| rv << element if element.kind_of? Element } rv.each do |element| @@ -865,7 +865,7 @@ module REXML end # Adds an element - # element:: + # element:: # if supplied, is either an Element, String, or # Source (see Element.initialize). If not supplied or nil, a # new, default Element will be constructed @@ -890,8 +890,8 @@ module REXML # Iterates through all of the child Elements, optionally filtering # them by a given XPath - # xpath:: - # optional. If supplied, this is a String XPath, and is used to + # xpath:: + # optional. If supplied, this is a String XPath, and is used to # filter the children, so that only matching children are yielded. Note # that XPaths are automatically filtered for Elements, so that # non-Element children will not be yielded @@ -908,8 +908,8 @@ module REXML def collect( xpath=nil, &block ) collection = [] - XPath::each( @element, xpath ) {|e| - collection << yield(e) if e.kind_of?(Element) + XPath::each( @element, xpath ) {|e| + collection << yield(e) if e.kind_of?(Element) } collection end @@ -944,7 +944,7 @@ module REXML # supplied XPath matches non-Element children. # doc = Document.new 'seanelliott' # doc.root.elements.to_a #-> [ , ] - # doc.root.elements.to_a("child::node()") #-> [ , ] + # doc.root.elements.to_a("child::node()") #-> [ , ] # XPath.match(doc.root, "child::node()") #-> [ sean, , elliott, ] def to_a( xpath=nil ) rv = XPath.match( @element, xpath ) @@ -964,7 +964,7 @@ module REXML # ATTRIBUTES # ######################################################################## - # A class that defines the set of Attributes of an Element and provides + # A class that defines the set of Attributes of an Element and provides # operations for accessing elements in that set. class Attributes < Hash # Constructor @@ -976,11 +976,11 @@ module REXML # Fetches an attribute value. If you want to get the Attribute itself, # use get_attribute() # name:: an XPath attribute name. Namespaces are relevant here. - # Returns:: + # Returns:: # the String value of the matching attribute, or +nil+ if no # matching attribute was found. This is the unnormalized value # (with entities expanded). - # + # # doc = Document.new "" # doc.root.attributes['att'] #-> '<' # doc.root.attributes['bar:att'] #-> '2' @@ -1006,7 +1006,7 @@ module REXML # Iterates over the attributes of an Element. Yields actual Attribute # nodes, not String values. - # + # # doc = Document.new '' # doc.root.attributes.each_attribute {|attr| # p attr.expanded_name+" => "+attr.value @@ -1033,7 +1033,7 @@ module REXML end # Fetches an attribute - # name:: + # name:: # the name by which to search for the attribute. Can be a # prefix:name namespace name. # Returns:: The first matching attribute, or nil if there was none. This @@ -1077,10 +1077,10 @@ module REXML # Sets an attribute, overwriting any existing attribute value by the # same name. Namespace is significant. # name:: the name of the attribute - # value:: + # value:: # (optional) If supplied, the value of the attribute. If # nil, any existing matching attribute is deleted. - # Returns:: + # Returns:: # Owning element # doc = Document.new "" # doc.root.attributes['y:foo'] = '2' @@ -1109,13 +1109,13 @@ module REXML old_attr[value.prefix] = value elsif old_attr.prefix != value.prefix # Check for conflicting namespaces - raise ParseException.new( + raise ParseException.new( "Namespace conflict in adding attribute \"#{value.name}\": "+ "Prefix \"#{old_attr.prefix}\" = "+ "\"#{@element.namespace(old_attr.prefix)}\" and prefix "+ - "\"#{value.prefix}\" = \"#{@element.namespace(value.prefix)}\"") if + "\"#{value.prefix}\" = \"#{@element.namespace(value.prefix)}\"") if value.prefix != "xmlns" and old_attr.prefix != "xmlns" and - @element.namespace( old_attr.prefix ) == + @element.namespace( old_attr.prefix ) == @element.namespace( value.prefix ) store value.name, { old_attr.prefix => old_attr, value.prefix => value } @@ -1125,7 +1125,7 @@ module REXML return @element end - # Returns an array of Strings containing all of the prefixes declared + # Returns an array of Strings containing all of the prefixes declared # by this set of # attributes. The array does not include the default # namespace declaration, if one exists. # doc = Document.new("" node.children.each { |child| diff --git a/lib/rexml/formatters/pretty.rb b/lib/rexml/formatters/pretty.rb index 84c442e8bb..17d217d1dc 100644 --- a/lib/rexml/formatters/pretty.rb +++ b/lib/rexml/formatters/pretty.rb @@ -48,7 +48,7 @@ module REXML if @ie_hack output << " " end - output << "/" + output << "/" else output << ">" # If compact and all children are text, and if the formatted output diff --git a/lib/rexml/formatters/transitive.rb b/lib/rexml/formatters/transitive.rb index 6083f0390b..3a52e03f01 100644 --- a/lib/rexml/formatters/transitive.rb +++ b/lib/rexml/formatters/transitive.rb @@ -31,7 +31,7 @@ module REXML output << ' '*@level if node.children.empty? output << " " if @ie_hack - output << "/" + output << "/" else output << ">" # If compact and all children are text, and if the formatted output diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb index fc9c4701c4..2d30e5fe92 100644 --- a/lib/rexml/functions.rb +++ b/lib/rexml/functions.rb @@ -48,7 +48,7 @@ module REXML # UNTESTED def Functions::local_name( node_set=nil ) get_namespace( node_set ) do |node| - return node.local_name + return node.local_name end end @@ -57,7 +57,7 @@ module REXML end def Functions::name( node_set=nil ) - get_namespace( node_set ) do |node| + get_namespace( node_set ) do |node| node.expanded_name end end @@ -66,7 +66,7 @@ module REXML def Functions::get_namespace( node_set = nil ) if node_set == nil yield @@context[:node] if defined? @@context[:node].namespace - else + else if node_set.respond_to? :each node_set.each { |node| yield node if defined? node.namespace } elsif node_set.respond_to? :namespace @@ -81,15 +81,15 @@ module REXML # # A number is converted to a string as follows # - # NaN is converted to the string NaN + # NaN is converted to the string NaN # - # positive zero is converted to the string 0 + # positive zero is converted to the string 0 # - # negative zero is converted to the string 0 + # negative zero is converted to the string 0 # - # positive infinity is converted to the string Infinity + # positive infinity is converted to the string Infinity # - # negative infinity is converted to the string -Infinity + # negative infinity is converted to the string -Infinity # # if the number is an integer, the number is represented in decimal form # as a Number with no decimal point and no leading zeros, preceded by a @@ -156,7 +156,7 @@ module REXML string(string).include?(string(test)) end - # Kouhei fixed this + # Kouhei fixed this def Functions::substring_before( string, test ) ruby_string = string(string) ruby_index = ruby_string.index(string(test)) @@ -166,7 +166,7 @@ module REXML ruby_string[ 0...ruby_index ] end end - + # Kouhei fixed this too def Functions::substring_after( string, test ) ruby_string = string(string) @@ -175,11 +175,11 @@ module REXML "" end - # Take equal portions of Mike Stok and Sean Russell; mix + # Take equal portions of Mike Stok and Sean Russell; mix # vigorously, and pour into a tall, chilled glass. Serves 10,000. def Functions::substring( string, start, length=nil ) ruby_string = string(string) - ruby_length = if length.nil? + ruby_length = if length.nil? ruby_string.length.to_f else number(length) @@ -188,15 +188,15 @@ module REXML # Handle the special cases return '' if ( - ruby_length.nan? or + ruby_length.nan? or ruby_start.nan? or ruby_start.infinite? ) infinite_length = ruby_length.infinite? == 1 ruby_length = ruby_string.length if infinite_length - - # Now, get the bounds. The XPath bounds are 1..length; the ruby bounds + + # Now, get the bounds. The XPath bounds are 1..length; the ruby bounds # are 0..length. Therefore, we have to offset the bounds by one. ruby_start = ruby_start.round - 1 ruby_length = ruby_length.round @@ -247,7 +247,7 @@ module REXML 0.upto(from.length - 1) { |pos| from_char = from[pos] unless map.has_key? from_char - map[from_char] = + map[from_char] = if pos < to.length to[pos] else @@ -359,7 +359,7 @@ module REXML nodes = [nodes] unless nodes.kind_of? Array nodes.inject(0) { |r,n| r += number(string(n)) } end - + def Functions::floor( number ) number(number).floor end diff --git a/lib/rexml/instruction.rb b/lib/rexml/instruction.rb index 50bf95d17a..f8b734a5b5 100644 --- a/lib/rexml/instruction.rb +++ b/lib/rexml/instruction.rb @@ -13,7 +13,7 @@ module REXML attr_accessor :target, :content # Constructs a new Instruction - # @param target can be one of a number of things. If String, then + # @param target can be one of a number of things. If String, then # the target of this instruction is set to this. If an Instruction, # then the Instruction is shallowly cloned (target and content are # copied). If a Source, then the source is scanned and parsed for @@ -37,7 +37,7 @@ module REXML def clone Instruction.new self end - + # == DEPRECATED # See the rexml/formatters package # diff --git a/lib/rexml/namespace.rb b/lib/rexml/namespace.rb index 8d43fc85ad..aeb339ee83 100644 --- a/lib/rexml/namespace.rb +++ b/lib/rexml/namespace.rb @@ -40,7 +40,7 @@ module REXML # source file. def fully_expanded_name ns = prefix - return "#{ns}:#@name" if ns.size > 0 + return "#{ns}:#@name" if ns.size > 0 return @name end end diff --git a/lib/rexml/node.rb b/lib/rexml/node.rb index eb39141944..85457f1ad0 100644 --- a/lib/rexml/node.rb +++ b/lib/rexml/node.rb @@ -57,7 +57,7 @@ module REXML } end - # Find (and return) first subnode (recursively) for which the block + # Find (and return) first subnode (recursively) for which the block # evaluates to true. Returns +nil+ if none was found. def find_first_recursive(&block) # :yields: node each_recursive {|node| diff --git a/lib/rexml/output.rb b/lib/rexml/output.rb index 997f2b117d..b7f17b9dff 100644 --- a/lib/rexml/output.rb +++ b/lib/rexml/output.rb @@ -3,7 +3,7 @@ require 'rexml/encoding' module REXML class Output include Encoding - + attr_reader :encoding def initialize real_IO, encd="iso-8859-1" diff --git a/lib/rexml/parent.rb b/lib/rexml/parent.rb index a20aaaef6b..7ed1761654 100644 --- a/lib/rexml/parent.rb +++ b/lib/rexml/parent.rb @@ -6,14 +6,14 @@ module REXML # object. class Parent < Child include Enumerable - + # Constructor # @param parent if supplied, will be set as the parent of this object def initialize parent=nil super(parent) @children = [] end - + def add( object ) #puts "PARENT GOTS #{size} CHILDREN" object.parent = self @@ -21,47 +21,47 @@ module REXML #puts "PARENT NOW GOTS #{size} CHILDREN" object end - + alias :push :add alias :<< :push - + def unshift( object ) object.parent = self @children.unshift object end - + def delete( object ) found = false @children.delete_if {|c| c.equal?(object) and found = true } object.parent = nil if found end - + def each(&block) @children.each(&block) end - + def delete_if( &block ) @children.delete_if(&block) end - + def delete_at( index ) @children.delete_at index end - + def each_index( &block ) @children.each_index(&block) end - + # Fetches a child at a given index # @param index the Integer index of the child to fetch def []( index ) @children[index] end - + alias :each_child :each - - - + + + # Set an index entry. See Array.[]= # @param index the index of the element to set # @param opt either the object to set, or an Integer length @@ -71,7 +71,7 @@ module REXML args[-1].parent = self @children[*args[0..-2]] = args[-1] end - + # Inserts an child before another child # @param child1 this is either an xpath or an Element. If an Element, # child2 will be inserted before child1 in the child list of the parent. @@ -91,7 +91,7 @@ module REXML end self end - + # Inserts an child after another child # @param child1 this is either an xpath or an Element. If an Element, # child2 will be inserted after child1 in the child list of the parent. @@ -111,11 +111,11 @@ module REXML end self end - + def to_a @children.dup end - + # Fetches the index of a given child # @param child the child to get the index of # @return the index of the child, or nil if the object is not a child @@ -125,24 +125,24 @@ module REXML @children.find { |i| count += 1 ; i.hash == child.hash } count end - + # @return the number of children of this parent def size @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 + # @param replacement the child to insert into the nodelist (must be a # Child) def replace_child( to_replace, replacement ) @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 # Parent, including all descendants. def deep_clone @@ -156,9 +156,9 @@ module REXML end cl end - + alias :children :to_a - + def parent? true end diff --git a/lib/rexml/parseexception.rb b/lib/rexml/parseexception.rb index feb7a7e638..0481f72818 100644 --- a/lib/rexml/parseexception.rb +++ b/lib/rexml/parseexception.rb @@ -30,7 +30,7 @@ module REXML err << "Last 80 unconsumed characters:\n" err << @source.buffer[0..80].gsub(/\n/, ' ') end - + err end @@ -40,12 +40,12 @@ module REXML end def line - @source.current_line[2] if @source and defined? @source.current_line and + @source.current_line[2] if @source and defined? @source.current_line and @source.current_line end def context @source.current_line end - end + end end diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb index 162d029a62..2f758265bb 100644 --- a/lib/rexml/parsers/baseparser.rb +++ b/lib/rexml/parsers/baseparser.rb @@ -105,11 +105,11 @@ module REXML EREFERENCE = /&(?!#{NAME};)/ - DEFAULT_ENTITIES = { - 'gt' => [/>/, '>', '>', />/], - 'lt' => [/</, '<', '<', / [/"/, '"', '"', /"/], - "apos" => [/'/, "'", "'", /'/] + DEFAULT_ENTITIES = { + 'gt' => [/>/, '>', '>', />/], + 'lt' => [/</, '<', '<', / [/"/, '"', '"', /"/], + "apos" => [/'/, "'", "'", /'/] } @@ -180,9 +180,9 @@ module REXML # Peek at the +depth+ event in the stack. The first element on the stack # is at depth 0. If +depth+ is -1, will parse to the end of the input # stream and return the last event, which is always :end_document. - # Be aware that this causes the stream to be parsed up to the +depth+ - # event, so you can effectively pre-parse the entire document (pull the - # entire thing into memory) using this method. + # Be aware that this causes the stream to be parsed up to the +depth+ + # event, so you can effectively pre-parse the entire document (pull the + # entire thing into memory) using this method. def peek depth=0 raise %Q[Illegal argument "#{depth}"] if depth < -1 temp = [] @@ -265,7 +265,7 @@ module REXML if @document_status == :in_doctype md = @source.match(/\s*(.*?>)/um) case md[1] - when SYSTEMENTITY + when SYSTEMENTITY match = @source.match( SYSTEMENTITY, true )[1] return [ :externalentity, match ] @@ -344,7 +344,7 @@ module REXML #md = @source.match_to_consume( '>', CLOSE_MATCH) md = @source.match( CLOSE_MATCH, true ) raise REXML::ParseException.new( "Missing end tag for "+ - "'#{last_tag}' (got \"#{md[1]}\")", + "'#{last_tag}' (got \"#{md[1]}\")", @source) unless last_tag == md[1] return [ :end_element, last_tag ] elsif @source.buffer[1] == ?! @@ -377,7 +377,7 @@ module REXML unless md # Check for missing attribute quotes raise REXML::ParseException.new("missing attribute quote", @source) if @source.match(MISSING_ATTRIBUTE_QUOTES ) - raise REXML::ParseException.new("malformed XML: missing tag start", @source) + raise REXML::ParseException.new("malformed XML: missing tag start", @source) end attributes = {} prefixes = Set.new @@ -386,7 +386,7 @@ module REXML if md[4].size > 0 attrs = md[4].scan( ATTRIBUTE_PATTERN ) raise REXML::ParseException.new( "error parsing attributes: [#{attrs.join ', '}], excess = \"#$'\"", @source) if $' and $'.strip.size > 0 - attrs.each { |a,b,c,d,e| + attrs.each { |a,b,c,d,e| if b == "xmlns" if c == "xml" if d != "http://www.w3.org/XML/1998/namespace" @@ -409,10 +409,10 @@ module REXML raise REXML::ParseException.new( msg, @source, self) end - attributes[a] = e + attributes[a] = e } end - + # Verify that all of the prefixes have been defined for prefix in prefixes unless @nsstack.find{|k| k.member?(prefix)} @@ -466,7 +466,7 @@ module REXML # Doing it like this rather than in a loop improves the speed copy.gsub!( EREFERENCE, '&' ) entities.each do |key, value| - copy.gsub!( value, "&#{key};" ) unless entity_filter and + copy.gsub!( value, "&#{key};" ) unless entity_filter and entity_filter.include?(entity) end if entities copy.gsub!( EREFERENCE, '&' ) diff --git a/lib/rexml/parsers/pullparser.rb b/lib/rexml/parsers/pullparser.rb index 36dc7160c3..68a4ff7eae 100644 --- a/lib/rexml/parsers/pullparser.rb +++ b/lib/rexml/parsers/pullparser.rb @@ -68,7 +68,7 @@ module REXML event = @parser.pull case event[0] when :entitydecl - @entities[ event[1] ] = + @entities[ event[1] ] = event[2] unless event[2] =~ /PUBLIC|SYSTEM/ when :text unnormalized = @parser.unnormalize( event[1], @entities ) diff --git a/lib/rexml/parsers/sax2parser.rb b/lib/rexml/parsers/sax2parser.rb index 72131401c3..d0f0c5155e 100644 --- a/lib/rexml/parsers/sax2parser.rb +++ b/lib/rexml/parsers/sax2parser.rb @@ -20,7 +20,7 @@ module REXML def source @parser.source end - + def add_listener( listener ) @parser.add_listener( listener ) end @@ -44,7 +44,7 @@ module REXML # :entitydecl, :notationdecl, :cdata, :xmldecl, :comment # # There is an additional symbol that can be listened for: :progress. - # This will be called for every event generated, passing in the current + # This will be called for every event generated, passing in the current # stream position. # # Array contains regular expressions or strings which will be matched @@ -72,7 +72,7 @@ module REXML add([nil, nil, args[0]]) end end - + def deafen( listener=nil, &blok ) if listener @listeners.delete_if {|item| item[-1] == listener } @@ -81,10 +81,10 @@ module REXML @procs.delete_if {|item| item[-1] == blok } end end - + def parse @procs.each { |sym,match,block| block.call if sym == :start_document } - @listeners.each { |sym,match,block| + @listeners.each { |sym,match,block| block.start_document if sym == :start_document or sym.nil? } root = context = [] @@ -126,8 +126,8 @@ module REXML listeners = get_listeners( :start_element, event[1] ) # notify observers procs.each { |ob| ob.call( uri, local, event[1], event[2] ) } if procs - listeners.each { |ob| - ob.start_element( uri, local, event[1], event[2] ) + listeners.each { |ob| + ob.start_element( uri, local, event[1], event[2] ) } if listeners when :end_element @tag_stack.pop @@ -140,8 +140,8 @@ module REXML listeners = get_listeners( :end_element, event[1] ) # notify observers procs.each { |ob| ob.call( uri, local, event[1] ) } if procs - listeners.each { |ob| - ob.end_element( uri, local, event[1] ) + listeners.each { |ob| + ob.end_element( uri, local, event[1] ) } if listeners namespace_mapping = @namespace_stack.pop @@ -160,7 +160,7 @@ module REXML #handle( :characters, normalized ) copy = event[1].clone - esub = proc { |match| + esub = proc { |match| if @entities.has_key?($1) @entities[$1].gsub(Text::REFERENCE, &esub) else @@ -178,7 +178,7 @@ module REXML when :entitydecl @entities[ event[1] ] = event[2] if event.size == 3 handle( *event ) - when :processing_instruction, :comment, :attlistdecl, + when :processing_instruction, :comment, :attlistdecl, :elementdecl, :cdata, :notationdecl, :xmldecl handle( *event ) end @@ -193,8 +193,8 @@ module REXML listeners = get_listeners( symbol, tag ) # notify observers procs.each { |ob| ob.call( *arguments ) } if procs - listeners.each { |l| - l.send( symbol.to_s, *arguments ) + listeners.each { |l| + l.send( symbol.to_s, *arguments ) } if listeners end @@ -205,7 +205,7 @@ module REXML @procs.find_all do |sym, match, block| #puts sym.inspect+"=="+symbol.inspect+ "\t"+match.inspect+"=="+name.inspect+ "\t"+( (sym.nil? or symbol == sym) and ((name.nil? and match.nil?) or match.nil? or ( (name == match) or (match.kind_of? Regexp and name =~ match)))).to_s ( - (sym.nil? or symbol == sym) and + (sym.nil? or symbol == sym) and ((name.nil? and match.nil?) or match.nil? or ( (name == match) or (match.kind_of? Regexp and name =~ match) @@ -218,7 +218,7 @@ module REXML return nil if @listeners.size == 0 @listeners.find_all do |sym, match, block| ( - (sym.nil? or symbol == sym) and + (sym.nil? or symbol == sym) and ((name.nil? and match.nil?) or match.nil? or ( (name == match) or (match.kind_of? Regexp and name =~ match) @@ -237,7 +237,7 @@ module REXML end end - def get_namespace( prefix ) + def get_namespace( prefix ) uris = (@namespace_stack.find_all { |ns| not ns[prefix].nil? }) || (@namespace_stack.find { |ns| not ns[nil].nil? }) uris[-1][prefix] unless uris.nil? or 0 == uris.size diff --git a/lib/rexml/parsers/streamparser.rb b/lib/rexml/parsers/streamparser.rb index 256d0f611c..073fcc2c21 100644 --- a/lib/rexml/parsers/streamparser.rb +++ b/lib/rexml/parsers/streamparser.rb @@ -5,11 +5,11 @@ module REXML @listener = listener @parser = BaseParser.new( source ) end - + def add_listener( listener ) @parser.add_listener( listener ) end - + def parse # entity string while true diff --git a/lib/rexml/parsers/treeparser.rb b/lib/rexml/parsers/treeparser.rb index 30327d0dfd..7f618cb319 100644 --- a/lib/rexml/parsers/treeparser.rb +++ b/lib/rexml/parsers/treeparser.rb @@ -42,8 +42,8 @@ module REXML if @build_context[-1].instance_of? Text @build_context[-1] << event[1] else - @build_context.add( - Text.new(event[1], @build_context.whitespace, nil, true) + @build_context.add( + Text.new(event[1], @build_context.whitespace, nil, true) ) unless ( @build_context.ignore_whitespace_nodes and event[1].strip.size==0 diff --git a/lib/rexml/parsers/xpathparser.rb b/lib/rexml/parsers/xpathparser.rb index 49450b4aef..aafa72ab9e 100644 --- a/lib/rexml/parsers/xpathparser.rb +++ b/lib/rexml/parsers/xpathparser.rb @@ -53,8 +53,8 @@ module REXML string << "*" when :text string << "text()" - when :following, :following_sibling, - :ancestor, :ancestor_or_self, :descendant, + when :following, :following_sibling, + :ancestor, :ancestor_or_self, :descendant, :namespace, :preceding, :preceding_sibling string << "/" unless string.size == 0 string << op.to_s.tr("_", "-") @@ -97,7 +97,7 @@ module REXML case op when :node string << "node()" - when :attribute, :child, :following, :following_sibling, + when :attribute, :child, :following, :following_sibling, :ancestor, :ancestor_or_self, :descendant, :descendant_or_self, :namespace, :preceding, :preceding_sibling, :self, :parent string << "/" unless string.size == 0 @@ -249,7 +249,7 @@ module REXML parsed.concat(n) end - + if path.size > 0 if path[0] == ?/ if path[1] == ?/ @@ -332,12 +332,12 @@ module REXML predicates << expr[1..-2] if expr end #puts "PREDICATES = #{predicates.inspect}" - predicates.each{ |pred| + predicates.each{ |pred| #puts "ORING #{pred}" preds = [] parsed << :predicate parsed << preds - OrExpr(pred, preds) + OrExpr(pred, preds) } #puts "PREDICATES = #{predicates.inspect}" path @@ -600,13 +600,13 @@ module REXML #puts "LITERAL or NUMBER: #$1" varname = $1.nil? ? $2 : $1 path = $' - parsed << :literal + parsed << :literal parsed << (varname.include?('.') ? varname.to_f : varname.to_i) when LITERAL #puts "LITERAL or NUMBER: #$1" varname = $1.nil? ? $2 : $1 path = $' - parsed << :literal + parsed << :literal parsed << varname when /^\(/ #/ path, contents = get_group(path) @@ -649,7 +649,7 @@ module REXML return nil unless depth==0 [string[ind..-1], string[0..ind-1]] end - + def parse_args( string ) arguments = [] ind = 0 @@ -683,7 +683,7 @@ module REXML s = string[0,ind].strip arguments << s unless s == "" string = string[ind+1..-1] - ind = -1 + ind = -1 end end end diff --git a/lib/rexml/quickpath.rb b/lib/rexml/quickpath.rb index fd2ebdd0ca..95fc72b7c2 100644 --- a/lib/rexml/quickpath.rb +++ b/lib/rexml/quickpath.rb @@ -68,7 +68,7 @@ module REXML ns = $1 rest = $' elements.delete_if do |element| - !(element.kind_of? Element and + !(element.kind_of? Element and (element.expanded_name == name or (element.name == name and element.namespace == Functions.namespace_context[ns]))) @@ -135,16 +135,16 @@ module REXML matches = filter(elements.collect{|element| element.next_sibling}.uniq, rest) when "previous-sibling" - matches = filter(elements.collect{|element| + matches = filter(elements.collect{|element| element.previous_sibling}.uniq, rest ) end return matches.uniq end # A predicate filters a node-set with respect to an axis to produce a - # new node-set. For each node in the node-set to be filtered, the - # PredicateExpr is evaluated with that node as the context node, with - # the number of nodes in the node-set as the context size, and with the + # new node-set. For each node in the node-set to be filtered, the + # PredicateExpr is evaluated with that node as the context node, with + # the number of nodes in the node-set as the context size, and with the # proximity position of the node in the node-set with respect to the # axis as the context position; if PredicateExpr evaluates to true for # that node, the node is included in the new node-set; otherwise, it is @@ -157,7 +157,7 @@ module REXML # number, then the result will be converted as if by a call to the # boolean function. Thus a location path para[3] is equivalent to # para[position()=3]. - def QuickPath::predicate( elements, path ) + def QuickPath::predicate( elements, path ) ind = 1 bcount = 1 while bcount > 0 @@ -175,13 +175,13 @@ module REXML # Let's do some Ruby trickery to avoid some work: predicate.gsub!( /&/u, "&&" ) predicate.gsub!( /=/u, "==" ) - predicate.gsub!( /@(\w[-\w.]*)/u, 'attribute("\1")' ) + predicate.gsub!( /@(\w[-\w.]*)/u, 'attribute("\1")' ) predicate.gsub!( /\bmod\b/u, "%" ) predicate.gsub!( /\b(\w[-\w.]*\()/u ) { fname = $1 fname.gsub( /-/u, "_" ) } - + Functions.pair = [ 0, elements.size ] results = [] elements.each do |element| diff --git a/lib/rexml/rexml.rb b/lib/rexml/rexml.rb index 810af31356..ab2f44561b 100644 --- a/lib/rexml/rexml.rb +++ b/lib/rexml/rexml.rb @@ -5,20 +5,20 @@ # non-validating[http://www.w3.org/TR/2004/REC-xml-20040204/#sec-conformance] # toolkit with an intuitive API. REXML passes 100% of the non-validating Oasis # tests[http://www.oasis-open.org/committees/xml-conformance/xml-test-suite.shtml], -# and provides tree, stream, SAX2, pull, and lightweight APIs. REXML also -# includes a full XPath[http://www.w3c.org/tr/xpath] 1.0 implementation. Since +# and provides tree, stream, SAX2, pull, and lightweight APIs. REXML also +# includes a full XPath[http://www.w3c.org/tr/xpath] 1.0 implementation. Since # Ruby 1.8, REXML is included in the standard Ruby distribution. # # Main page:: http://www.germane-software.com/software/rexml # Author:: Sean Russell # Date:: 2008/019 # Version:: 3.1.7.3 -# +# # This API documentation can be downloaded from the REXML home page, or can # be accessed online[http://www.germane-software.com/software/rexml_doc] # # A tutorial is available in the REXML distribution in docs/tutorial.html, -# or can be accessed +# or can be accessed # online[http://www.germane-software.com/software/rexml/docs/tutorial.html] module REXML COPYRIGHT = "Copyright © 2001-2008 Sean Russell " diff --git a/lib/rexml/sax2listener.rb b/lib/rexml/sax2listener.rb index 9545b08a93..6830e4483a 100644 --- a/lib/rexml/sax2listener.rb +++ b/lib/rexml/sax2listener.rb @@ -1,11 +1,11 @@ module REXML # A template for stream parser listeners. # Note that the declarations (attlistdecl, elementdecl, etc) are trivially - # processed; REXML doesn't yet handle doctype entity declarations, so you + # processed; REXML doesn't yet handle doctype entity declarations, so you # have to parse them out yourself. # === Missing methods from SAX2 # ignorable_whitespace - # === Methods extending SAX2 + # === Methods extending SAX2 # +WARNING+ # These methods are certainly going to change, until DTDs are fully # supported. Be aware of this. @@ -58,7 +58,7 @@ module REXML # The argument passed to this method is an array of the entity # declaration. It can be in a number of formats, but in general it # returns (example, result): - # + # # ["%", "YN", "'\"Yes\"'", "\""] # # ["%", "YN", "'Yes'", "s"] @@ -93,5 +93,5 @@ module REXML end def progress position end - end + end end diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb index d4335138a1..3f6d4ffa26 100644 --- a/lib/rexml/source.rb +++ b/lib/rexml/source.rb @@ -69,9 +69,9 @@ module REXML # usual scan() method. For one thing, the pattern argument has some # requirements; for another, the source can be consumed. You can easily # confuse this method. Originally, the patterns were easier - # to construct and this method more robust, because this method - # generated search regexes on the fly; however, this was - # computationally expensive and slowed down the entire REXML package + # to construct and this method more robust, because this method + # generated search regexes on the fly; however, this was + # computationally expensive and slowed down the entire REXML package # considerably, since this is by far the most commonly called method. # @param pattern must be a Regexp, and must be in the form of # /^\s*(#{your pattern, with no groups})(.*)/. The first group @@ -194,7 +194,7 @@ module REXML def read begin str = @source.readline(@line_break) - str = decode(str) if @to_utf and str + str = decode(str) if @to_utf and str @buffer << str if not @to_utf and @buffer.respond_to? :force_encoding @buffer.force_encoding Encoding::UTF_8 @@ -225,7 +225,7 @@ module REXML rv.taint rv end - + def empty? super and ( @source.nil? || @source.eof? ) end diff --git a/lib/rexml/streamlistener.rb b/lib/rexml/streamlistener.rb index 3a4ef9f769..619c529578 100644 --- a/lib/rexml/streamlistener.rb +++ b/lib/rexml/streamlistener.rb @@ -1,14 +1,14 @@ module REXML # A template for stream parser listeners. # Note that the declarations (attlistdecl, elementdecl, etc) are trivially - # processed; REXML doesn't yet handle doctype entity declarations, so you + # processed; REXML doesn't yet handle doctype entity declarations, so you # have to parse them out yourself. module StreamListener # Called when a tag is encountered. # @p name the tag name # @p attrs an array of arrays of attribute/value pairs, suitable for # use with assoc or rassoc. IE, - # will result in + # will result in # tag_start( "tag", # [["attr1","value1"],["attr2","value2"]]) def tag_start name, attrs end @@ -56,7 +56,7 @@ module REXML # The argument passed to this method is an array of the entity # declaration. It can be in a number of formats, but in general it # returns (example, result): - # + # # ["%", "YN", "'\"Yes\"'", "\""] # # ["%", "YN", "'Yes'", "s"] diff --git a/lib/rexml/text.rb b/lib/rexml/text.rb index fac5ac3e41..d09dc3ac54 100644 --- a/lib/rexml/text.rb +++ b/lib/rexml/text.rb @@ -19,7 +19,7 @@ module REXML attr_accessor :raw NEEDS_A_SECOND_CHECK = /(<|&((#{Entity::NAME});|(#0*((?:\d+)|(?:x[a-fA-F0-9]+)));)?)/um - NUMERICENTITY = /�*((?:\d+)|(?:x[a-fA-F0-9]+));/ + NUMERICENTITY = /�*((?:\d+)|(?:x[a-fA-F0-9]+));/ VALID_CHAR = [ 0x9, 0xA, 0xD, (0x20..0xD7FF), @@ -50,25 +50,25 @@ module REXML | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 - )*$/nx; + )*$/nx; end # Constructor # +arg+ if a String, the content is set to the String. If a Text, - # the object is shallowly cloned. + # the object is shallowly cloned. # # +respect_whitespace+ (boolean, false) if true, whitespace is # respected # # +parent+ (nil) if this is a Parent object, the parent - # will be set to this. + # will be set to this. # # +raw+ (nil) This argument can be given three values. - # If true, then the value of used to construct this object is expected to - # contain no unescaped XML markup, and REXML will not change the text. If + # If true, then the value of used to construct this object is expected to + # contain no unescaped XML markup, and REXML will not change the text. If # this value is false, the string may contain any characters, and REXML will # escape any and all defined entities whose values are contained in the - # text. If this value is nil (the default), then the raw value of the + # 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 @@ -89,14 +89,14 @@ module REXML # In the last example, the +entity_filter+ argument is ignored. # # +pattern+ INTERNAL USE ONLY - def initialize(arg, respect_whitespace=false, parent=nil, raw=nil, + def initialize(arg, respect_whitespace=false, parent=nil, raw=nil, entity_filter=nil, illegal=NEEDS_A_SECOND_CHECK ) @raw = false if parent super( parent ) - @raw = parent.raw + @raw = parent.raw else @parent = nil end @@ -208,12 +208,12 @@ module REXML # escaped, meaning that it is a valid XML text node string, and all # entities that can be escaped, have been inserted. This method respects # the entity filter set in the constructor. - # - # # Assume that the entity "s" is defined to be "sean", and that the + # + # # 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 = Text.new( "< & sean russell", false, nil, false, ['s'] ) # t.to_s #-> "< & &s; russell" - # t = Text.new( "< & &s; russell", false, nil, false ) + # t = Text.new( "< & &s; russell", false, nil, false ) # t.to_s #-> "< & &s; russell" # u = Text.new( "sean russell", false, nil, true ) # u.to_s #-> "sean russell" @@ -233,9 +233,9 @@ module REXML # console. This ignores the 'raw' attribute setting, and any # entity_filter. # - # # Assume that the entity "s" is defined to be "sean", and that the + # # 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 = Text.new( "< & sean russell", false, nil, false, ['s'] ) # t.value #-> "< & sean russell" # t = Text.new( "< & &s; russell", false, nil, false ) # t.value #-> "< & sean russell" @@ -246,7 +246,7 @@ module REXML @unnormalized = Text::unnormalize( @string, doctype ) end - # Sets the contents of this text node. This expects the text to be + # Sets the contents of this text node. This expects the text to be # unnormalized. It returns self. # # e = Element.new( "a" ) @@ -259,7 +259,7 @@ module REXML @normalized = nil @raw = false end - + def wrap(string, width, addnewline=false) # Recursively wrap string at width. return string if string.length <= width @@ -282,11 +282,11 @@ module REXML new_string.strip! unless indentfirstline return new_string end - + # == DEPRECATED # See REXML::Formatters # - def write( writer, indent=-1, transitive=false, ie_hack=false ) + def write( writer, indent=-1, transitive=false, ie_hack=false ) Kernel.warn("#{self.class.name}.write is deprecated. See REXML::Formatters") formatter = if indent > -1 REXML::Formatters::Pretty.new( indent ) @@ -337,7 +337,7 @@ module REXML if copy =~ illegal raise ParseException.new( "malformed text: Illegal character #$& in \"#{copy}\"" ) end if illegal - + copy.gsub!( /\r\n?/, "\n" ) if copy.include? ?& copy.gsub!( SETUTITSBUS[0], SLAICEPS[0] ) @@ -365,8 +365,8 @@ module REXML if doctype # Replace all ampersands that aren't part of an entity doctype.entities.each_value do |entity| - copy = copy.gsub( entity.value, - "&#{entity.name};" ) if entity.value and + copy = copy.gsub( entity.value, + "&#{entity.name};" ) if entity.value and not( entity_filter and entity_filter.include?(entity) ) end else diff --git a/lib/rexml/validation/relaxng.rb b/lib/rexml/validation/relaxng.rb index 2b863710b4..2441901d7b 100644 --- a/lib/rexml/validation/relaxng.rb +++ b/lib/rexml/validation/relaxng.rb @@ -79,7 +79,7 @@ module REXML when "mixed" states << Interleave.new( self ) states[-2] << states[-1] - states[-1] << TEXT + states[-1] << TEXT when "define" states << [ event[2]["name"] ] when "ref" @@ -102,7 +102,7 @@ module REXML case event[1] when "element", "attribute" states[-1] << event - when "zeroOrMore", "oneOrMore", "choice", "optional", + when "zeroOrMore", "oneOrMore", "choice", "optional", "interleave", "group", "mixed" states.pop when "define" @@ -139,7 +139,7 @@ module REXML @events.each {|s| s.reset if s.kind_of? State } end - def previous=( previous ) + def previous=( previous ) @previous << previous end @@ -183,7 +183,7 @@ module REXML end def inspect - "< #{to_s} #{@events.collect{|e| + "< #{to_s} #{@events.collect{|e| pre = e == @events[@current] ? '#' : '' pre + e.inspect unless self == e }.join(', ')} >" @@ -201,15 +201,15 @@ module REXML protected def expand_ref_in( arry, ind ) new_events = [] - @references[ arry[ind].to_s ].each{ |evt| + @references[ arry[ind].to_s ].each{ |evt| add_event_to_arry(new_events,evt) } arry[ind,1] = new_events end - def add_event_to_arry( arry, evt ) + def add_event_to_arry( arry, evt ) evt = generate_event( evt ) - if evt.kind_of? String + if evt.kind_of? String arry[-1].event_arg = evt if arry[-1].kind_of? Event and @value @value = false else @@ -272,7 +272,7 @@ module REXML end def matches?(event) - @events[@current].matches?(event) || + @events[@current].matches?(event) || (@current == 0 and @previous[-1].matches?(event)) end @@ -319,7 +319,7 @@ module REXML end def reset - super + super @ord = 0 end @@ -345,7 +345,7 @@ module REXML end def matches?( event ) - @events[@current].matches?(event) || + @events[@current].matches?(event) || (@current == 0 and @ord > 0 and @previous[-1].matches?(event)) end @@ -412,7 +412,7 @@ module REXML #puts "IN CHOICE EXPECTED" #puts "EVENTS = #{@events.inspect}" return [@events[@current]] if @events.size > 0 - return @choices.collect do |x| + return @choices.collect do |x| if x[0].kind_of? State x[0].expected else @@ -426,12 +426,12 @@ module REXML end protected - def add_event_to_arry( arry, evt ) + def add_event_to_arry( arry, evt ) if evt.kind_of? State or evt.class == Ref arry << [evt] - elsif evt[0] == :text + elsif evt[0] == :text if arry[-1] and - arry[-1][-1].kind_of?( Event ) and + arry[-1][-1].kind_of?( Event ) and arry[-1][-1].event_type == :text and @value arry[-1][-1].event_arg = evt[1] @@ -478,7 +478,7 @@ module REXML @choices[idx] = old @choice += 1 end - + #puts "In next with #{event.inspect}." #puts "events is #{@events.inspect}" @events = [] unless @events @@ -490,7 +490,7 @@ module REXML next_current(event) unless @events[@current] return nil unless @events[@current] - expand_ref_in( @events, @current ) if @events[@current].class == Ref + expand_ref_in( @events, @current ) if @events[@current].class == Ref #puts "In next with #{event.inspect}." #puts "Next (#@current) is #{@events[@current]}" if ( @events[@current].kind_of? State ) @@ -530,7 +530,7 @@ module REXML #puts "IN CHOICE EXPECTED" #puts "EVENTS = #{@events.inspect}" return [@events[@current]] if @events[@current] - return @choices[@choice..-1].collect do |x| + return @choices[@choice..-1].collect do |x| if x[0].kind_of? State x[0].expected else diff --git a/lib/rexml/validation/validation.rb b/lib/rexml/validation/validation.rb index 93f5bfb329..f0ffa78912 100644 --- a/lib/rexml/validation/validation.rb +++ b/lib/rexml/validation/validation.rb @@ -14,7 +14,7 @@ module REXML def dump puts @root.inspect end - def validate( event ) + def validate( event ) #puts "Current: #@current" #puts "Event: #{event.inspect}" @attr_stack = [] unless defined? @attr_stack @@ -33,12 +33,12 @@ module REXML sattr = [:start_attribute, nil] eattr = [:end_attribute] text = [:text, nil] - k,v = event[2].find { |key,value| + k,v = event[2].find { |key,value| sattr[1] = key #puts "Looking for #{sattr.inspect}" m = @current.next( sattr ) #puts "Got #{m.inspect}" - if m + if m # If the state has text children... #puts "Looking for #{eattr.inspect}" #puts "Expect #{m.expected}" diff --git a/lib/rexml/xpath.rb b/lib/rexml/xpath.rb index b22969ec8c..5f7ecefe29 100644 --- a/lib/rexml/xpath.rb +++ b/lib/rexml/xpath.rb @@ -64,7 +64,7 @@ module REXML parser.parse(path, element).each( &block ) end - # Returns an array of nodes matching a given XPath. + # Returns an array of nodes matching a given XPath. def XPath::match element, path=nil, namespaces=nil, variables={} parser = XPathParser.new parser.namespaces = namespaces diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb index ead5adaf7f..11950ecd93 100644 --- a/lib/rexml/xpath_parser.rb +++ b/lib/rexml/xpath_parser.rb @@ -88,7 +88,7 @@ module REXML case path[0] when :document - # do nothing + # do nothing return first( path[1..-1], node ) when :child for c in node.children @@ -123,7 +123,7 @@ module REXML end - def match( path_stack, nodeset ) + def match( path_stack, nodeset ) #puts "MATCH: path_stack = #{path_stack.inspect}" #puts "MATCH: nodeset = #{nodeset.inspect}" r = expr( path_stack, nodeset ) @@ -136,7 +136,7 @@ module REXML # Returns a String namespace for a node, given a prefix # The rules are: - # + # # 1. Use the supplied namespace mapping first. # 2. If no mapping was supplied, use the context node to look up the namespace def get_namespace( node, prefix ) @@ -187,8 +187,8 @@ module REXML #puts "node.namespace == #{ns.inspect} => #{node.namespace == ns}" end end - !(node.node_type == :element and - node.name == name and + !(node.node_type == :element and + node.name == name and node.namespace == ns ) end node_types = ELEMENTS @@ -205,7 +205,7 @@ module REXML when :processing_instruction target = path_stack.shift nodeset.delete_if do |node| - (node.node_type != :processing_instruction) or + (node.node_type != :processing_instruction) or ( target!='' and ( node.target != target ) ) end @@ -231,7 +231,7 @@ module REXML when :literal return path_stack.shift - + when :attribute new_nodeset = [] case path_stack.shift @@ -481,23 +481,23 @@ module REXML when :function func_name = path_stack.shift.tr('-','_') arguments = path_stack.shift - #puts "FUNCTION 0: #{func_name}(#{arguments.collect{|a|a.inspect}.join(', ')})" + #puts "FUNCTION 0: #{func_name}(#{arguments.collect{|a|a.inspect}.join(', ')})" subcontext = context ? nil : { :size => nodeset.size } res = [] cont = context - nodeset.each_with_index { |n, i| + nodeset.each_with_index { |n, i| if subcontext subcontext[:node] = n subcontext[:index] = i cont = subcontext end arg_clone = arguments.dclone - args = arg_clone.collect { |arg| + args = arg_clone.collect { |arg| #puts "FUNCTION 1: Calling expr( #{arg.inspect}, [#{n.inspect}] )" - expr( arg, [n], cont ) + expr( arg, [n], cont ) } - #puts "FUNCTION 2: #{func_name}(#{args.collect{|a|a.inspect}.join(', ')})" + #puts "FUNCTION 2: #{func_name}(#{args.collect{|a|a.inspect}.join(', ')})" Functions.context = cont res << Functions.send( func_name, *args ) #puts "FUNCTION 3: #{res[-1].inspect}" @@ -515,10 +515,10 @@ module REXML # FIXME # The next two methods are BAD MOJO! # This is my achilles heel. If anybody thinks of a better - # way of doing this, be my guest. This really sucks, but + # way of doing this, be my guest. This really sucks, but # it is a wonder it works at all. # ######################################################## - + def descendant_or_self( path_stack, nodeset ) rs = [] #puts "#"*80 @@ -547,7 +547,7 @@ module REXML # Reorders an array of nodes so that they are in document order # It tries to do this efficiently. # - # FIXME: I need to get rid of this, but the issue is that most of the XPath + # FIXME: I need to get rid of this, but the issue is that most of the XPath # interpreter functions as a filter, which means that we lose context going # in and out of function calls. If I knew what the index of the nodes was, # I wouldn't have to do this. Maybe add a document IDX for each node? @@ -555,7 +555,7 @@ module REXML def document_order( array_of_nodes ) new_arry = [] array_of_nodes.each { |node| - node_idx = [] + node_idx = [] np = node.node_type == :attribute ? node.element : node while np.parent and np.parent.node_type == :element node_idx << np.parent.index( np ) @@ -579,7 +579,7 @@ module REXML # Builds a nodeset of all of the preceding nodes of the supplied node, # in reverse document order - # preceding:: includes every element in the document that precedes this node, + # preceding:: includes every element in the document that precedes this node, # except for ancestors def preceding( node ) #puts "IN PRECEDING" @@ -609,9 +609,9 @@ module REXML #puts "NODE: #{node.inspect}" #puts "PREVIOUS NODE: #{node.previous_sibling_node.inspect}" #puts "PARENT NODE: #{node.parent}" - psn = node.previous_sibling_node + psn = node.previous_sibling_node if psn.nil? - if node.parent.nil? or node.parent.class == Document + if node.parent.nil? or node.parent.class == Document return nil end return node.parent @@ -647,9 +647,9 @@ module REXML end def next_sibling_node(node) - psn = node.next_sibling_node + psn = node.next_sibling_node while psn.nil? - if node.parent.nil? or node.parent.class == Document + if node.parent.nil? or node.parent.class == Document return nil end node = node.parent -- cgit v1.2.3