mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Cross-ported the REXML changes (3.0.8) from the development branch to the
stable branch. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
db0fac0266
commit
abe1214b3d
12 changed files with 946 additions and 891 deletions
|
@ -146,6 +146,12 @@ module REXML
|
||||||
def node_type
|
def node_type
|
||||||
:attribute
|
:attribute
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
rv = ""
|
||||||
|
write( rv )
|
||||||
|
rv
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
#vim:ts=2 sw=2 noexpandtab:
|
#vim:ts=2 sw=2 noexpandtab:
|
||||||
|
|
|
@ -59,7 +59,7 @@ module REXML
|
||||||
# c = CData.new( " Some text " )
|
# c = CData.new( " Some text " )
|
||||||
# c.write( $stdout ) #-> <![CDATA[ Some text ]]>
|
# c.write( $stdout ) #-> <![CDATA[ Some text ]]>
|
||||||
def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
|
def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
|
||||||
indent( output, indent )
|
indent( output, indent ) unless transitive
|
||||||
output << START
|
output << START
|
||||||
output << @string
|
output << @string
|
||||||
output << STOP
|
output << STOP
|
||||||
|
|
|
@ -32,11 +32,12 @@ module REXML
|
||||||
# # <!DOCTYPE foo '-//I/Hate/External/IDs'>
|
# # <!DOCTYPE foo '-//I/Hate/External/IDs'>
|
||||||
# dt = DocType.new( doctype_to_clone )
|
# dt = DocType.new( doctype_to_clone )
|
||||||
# # Incomplete. Shallow clone of doctype
|
# # Incomplete. Shallow clone of doctype
|
||||||
# source = Source.new( '<!DOCTYPE foo "bar">' )
|
#
|
||||||
# dt = DocType.new( source )
|
# +Note+ that the constructor:
|
||||||
# # <!DOCTYPE foo "bar">
|
#
|
||||||
# dt = DocType.new( source, some_document )
|
# Doctype.new( Source.new( "<!DOCTYPE foo 'bar'>" ) )
|
||||||
# # Creates a doctype, and adds to the supplied document
|
#
|
||||||
|
# is _deprecated_. Do not use it. It will probably disappear.
|
||||||
def initialize( first, parent=nil )
|
def initialize( first, parent=nil )
|
||||||
@entities = DEFAULT_ENTITIES
|
@entities = DEFAULT_ENTITIES
|
||||||
@long_name = @uri = nil
|
@long_name = @uri = nil
|
||||||
|
@ -54,6 +55,15 @@ module REXML
|
||||||
@external_id = first[1]
|
@external_id = first[1]
|
||||||
@long_name = first[2]
|
@long_name = first[2]
|
||||||
@uri = first[3]
|
@uri = first[3]
|
||||||
|
elsif first.kind_of? Source
|
||||||
|
super( parent )
|
||||||
|
parser = Parsers::BaseParser.new( first )
|
||||||
|
event = parser.pull
|
||||||
|
if event[0] == :start_doctype
|
||||||
|
@name, @external_id, @long_name, @uri, = event[1..-1]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
super()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -176,6 +176,7 @@ module REXML
|
||||||
tag_stack = []
|
tag_stack = []
|
||||||
in_doctype = false
|
in_doctype = false
|
||||||
entities = nil
|
entities = nil
|
||||||
|
begin
|
||||||
while true
|
while true
|
||||||
event = parser.pull
|
event = parser.pull
|
||||||
case event[0]
|
case event[0]
|
||||||
|
@ -237,6 +238,9 @@ module REXML
|
||||||
x = XMLDecl.new( event[1], event[2], event[3] )
|
x = XMLDecl.new( event[1], event[2], event[3] )
|
||||||
build_context.add( x )
|
build_context.add( x )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
raise ParseException.new( $!.message, parser.source, parser, $! )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -67,6 +67,22 @@ module REXML
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
rv = "<#@expanded_name"
|
||||||
|
|
||||||
|
@attributes.each_attribute do |attr|
|
||||||
|
rv << " "
|
||||||
|
attr.write( rv, 0 )
|
||||||
|
end unless @attributes.empty?
|
||||||
|
|
||||||
|
if children.size > 0
|
||||||
|
rv << " ... </>"
|
||||||
|
else
|
||||||
|
rv << "/>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# Creates a shallow copy of self.
|
# Creates a shallow copy of self.
|
||||||
# d = Document.new "<a><b/><b/><c><d/></c></a>"
|
# d = Document.new "<a><b/><b/><c><d/></c></a>"
|
||||||
# new_a = d.root.clone
|
# new_a = d.root.clone
|
||||||
|
@ -643,7 +659,7 @@ module REXML
|
||||||
end
|
end
|
||||||
writer << "/"
|
writer << "/"
|
||||||
else
|
else
|
||||||
if transitive and indent>-1 and !@children[0].kind_of? Text
|
if transitive and indent>-1 and !@children[0].instance_of? Text
|
||||||
writer << "\n"
|
writer << "\n"
|
||||||
indent writer, indent+1
|
indent writer, indent+1
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ module REXML
|
||||||
array_utf8 = content.unpack('U*')
|
array_utf8 = content.unpack('U*')
|
||||||
array_enc = []
|
array_enc = []
|
||||||
array_utf8.each do |num|
|
array_utf8.each do |num|
|
||||||
if num <= 0xFF
|
if num <= 0x7F
|
||||||
array_enc << num
|
array_enc << num
|
||||||
else
|
else
|
||||||
# Numeric entity (&#nnnn;); shard by Stefan Scholl
|
# Numeric entity (&#nnnn;); shard by Stefan Scholl
|
||||||
|
|
|
@ -331,11 +331,17 @@ module REXML
|
||||||
elsif object == false
|
elsif object == false
|
||||||
Float(0)
|
Float(0)
|
||||||
elsif object.kind_of? Array
|
elsif object.kind_of? Array
|
||||||
string( object ).to_f
|
number(string( object ))
|
||||||
elsif object.kind_of? Float
|
elsif object.kind_of? Float
|
||||||
object
|
object
|
||||||
else
|
else
|
||||||
|
str = string( object )
|
||||||
|
#puts "STRING OF #{object.inspect} = #{str}"
|
||||||
|
if str =~ /^\d+/
|
||||||
object.to_s.to_f
|
object.to_s.to_f
|
||||||
|
else
|
||||||
|
(0.0 / 0.0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,13 @@ module REXML
|
||||||
end
|
end
|
||||||
|
|
||||||
def position
|
def position
|
||||||
@source.current_line[0] if @source and @source.current_line
|
@source.current_line[0] if @source and defined? @source.current_line and
|
||||||
|
@source.current_line
|
||||||
end
|
end
|
||||||
|
|
||||||
def line
|
def line
|
||||||
@source.current_line[2] if @source and @source.current_line
|
@source.current_line[2] if @source and defined? @source.current_line and
|
||||||
|
@source.current_line
|
||||||
end
|
end
|
||||||
|
|
||||||
def context
|
def context
|
||||||
|
|
|
@ -100,6 +100,8 @@ module REXML
|
||||||
self.stream = source
|
self.stream = source
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr_reader :source
|
||||||
|
|
||||||
def stream=( source )
|
def stream=( source )
|
||||||
if source.kind_of? String
|
if source.kind_of? String
|
||||||
@source = Source.new(source)
|
@source = Source.new(source)
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
#
|
#
|
||||||
# Main page:: http://www.germane-software.com/software/rexml
|
# Main page:: http://www.germane-software.com/software/rexml
|
||||||
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
|
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
|
||||||
# Version:: 3.0.4
|
# Version:: @ANT_VERSION@
|
||||||
# Date:: +2004/115
|
# Date:: @ANT_DATE@
|
||||||
#
|
#
|
||||||
# This API documentation can be downloaded from the REXML home page, or can
|
# This API documentation can be downloaded from the REXML home page, or can
|
||||||
# be accessed online[http://www.germane-software.com/software/rexml_doc]
|
# be accessed online[http://www.germane-software.com/software/rexml_doc]
|
||||||
|
@ -21,6 +21,6 @@
|
||||||
# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
|
# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
|
||||||
module REXML
|
module REXML
|
||||||
Copyright = "Copyright © 2001, 2002, 2003, 2004 Sean Russell <ser@germane-software.com>"
|
Copyright = "Copyright © 2001, 2002, 2003, 2004 Sean Russell <ser@germane-software.com>"
|
||||||
Date = "+2004/115"
|
Date = "@ANT_DATE@"
|
||||||
Version = "3.0.4"
|
Version = "@ANT_VERSION@"
|
||||||
end
|
end
|
||||||
|
|
|
@ -194,7 +194,7 @@ module REXML
|
||||||
@raw = false
|
@raw = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def indent(string, level=1, style="\t", indentfirstline=true)
|
def indent_text(string, level=1, style="\t", indentfirstline=true)
|
||||||
return string if level < 0
|
return string if level < 0
|
||||||
new_string = ''
|
new_string = ''
|
||||||
string.each { |line|
|
string.each { |line|
|
||||||
|
@ -211,7 +211,7 @@ module REXML
|
||||||
if not (@parent and @parent.whitespace) then
|
if not (@parent and @parent.whitespace) then
|
||||||
s = wrap(s, 60, false) if @parent and @parent.context[:wordwrap] == :all
|
s = wrap(s, 60, false) if @parent and @parent.context[:wordwrap] == :all
|
||||||
if @parent and not @parent.context[:indentstyle].nil? and indent > 0 and s.count("\n") > 0
|
if @parent and not @parent.context[:indentstyle].nil? and indent > 0 and s.count("\n") > 0
|
||||||
s = indent(s, indent, @parent.context[:indentstyle], false)
|
s = indent_text(s, indent, @parent.context[:indentstyle], false)
|
||||||
end
|
end
|
||||||
s.squeeze!(" \n\t") if @parent and !@parent.whitespace
|
s.squeeze!(" \n\t") if @parent and !@parent.whitespace
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,7 +49,7 @@ module REXML
|
||||||
while ( path_stack.size > 0 and nodeset.size > 0 )
|
while ( path_stack.size > 0 and nodeset.size > 0 )
|
||||||
#puts "PARSE: #{path_stack.inspect} '#{nodeset.collect{|n|n.class}.inspect}'"
|
#puts "PARSE: #{path_stack.inspect} '#{nodeset.collect{|n|n.class}.inspect}'"
|
||||||
nodeset = internal_parse( path_stack, nodeset )
|
nodeset = internal_parse( path_stack, nodeset )
|
||||||
#puts "NODESET: #{nodeset.size}"
|
#puts "NODESET: #{nodeset}"
|
||||||
#puts "PATH_STACK: #{path_stack.inspect}"
|
#puts "PATH_STACK: #{path_stack.inspect}"
|
||||||
end
|
end
|
||||||
nodeset
|
nodeset
|
||||||
|
@ -136,7 +136,6 @@ module REXML
|
||||||
return literal
|
return literal
|
||||||
|
|
||||||
when :attribute
|
when :attribute
|
||||||
#puts ":ATTRIBUTE"
|
|
||||||
new_nodeset = []
|
new_nodeset = []
|
||||||
case path_stack.shift
|
case path_stack.shift
|
||||||
when :qname
|
when :qname
|
||||||
|
@ -344,14 +343,20 @@ module REXML
|
||||||
eq = predicate.shift
|
eq = predicate.shift
|
||||||
left = Predicate( predicate.shift, node )
|
left = Predicate( predicate.shift, node )
|
||||||
right = Predicate( predicate.shift, node )
|
right = Predicate( predicate.shift, node )
|
||||||
|
#puts "LEFT = #{left.inspect}"
|
||||||
|
#puts "RIGHT = #{right.inspect}"
|
||||||
return equality_relational_compare( left, eq, right )
|
return equality_relational_compare( left, eq, right )
|
||||||
|
|
||||||
when :div, :mod, :mult, :plus, :minus
|
when :div, :mod, :mult, :plus, :minus
|
||||||
op = predicate.shift
|
op = predicate.shift
|
||||||
left = Predicate( predicate.shift, node )
|
left = Predicate( predicate.shift, node )
|
||||||
right = Predicate( predicate.shift, node )
|
right = Predicate( predicate.shift, node )
|
||||||
|
#puts "LEFT = #{left.inspect}"
|
||||||
|
#puts "RIGHT = #{right.inspect}"
|
||||||
left = Functions::number( left )
|
left = Functions::number( left )
|
||||||
right = Functions::number( right )
|
right = Functions::number( right )
|
||||||
|
#puts "LEFT = #{left.inspect}"
|
||||||
|
#puts "RIGHT = #{right.inspect}"
|
||||||
case op
|
case op
|
||||||
when :div
|
when :div
|
||||||
return left.to_f / right.to_f
|
return left.to_f / right.to_f
|
||||||
|
@ -472,8 +477,12 @@ module REXML
|
||||||
end
|
end
|
||||||
when /^\d+(\.\d+)?$/
|
when /^\d+(\.\d+)?$/
|
||||||
b = Functions::number( b )
|
b = Functions::number( b )
|
||||||
|
#puts "B = #{b.inspect}"
|
||||||
for v in a
|
for v in a
|
||||||
|
#puts "v = #{v.inspect}"
|
||||||
v = Functions::number(v)
|
v = Functions::number(v)
|
||||||
|
#puts "v = #{v.inspect}"
|
||||||
|
#puts compare(v,op,b)
|
||||||
return true if compare( v, op, b )
|
return true if compare( v, op, b )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue