summaryrefslogtreecommitdiff
path: root/lib/rexml/text.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-01 05:43:50 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-01 05:43:50 +0000
commit1448668244c81cfc720bcdfa93af352a17cc230f (patch)
tree550af4707b22d099f4d8393e29ef6da424aca813 /lib/rexml/text.rb
parent96e7713754c477fe98806b905301356371accb68 (diff)
* lib/rexml: 1.9 patch from Sam Ruby mentioned in his blog:
<http://intertwingly.net/blog/2007/12/31/Porting-REXML-to-Ruby-1-9> [ruby-core:14639] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/text.rb')
-rw-r--r--lib/rexml/text.rb43
1 files changed, 15 insertions, 28 deletions
diff --git a/lib/rexml/text.rb b/lib/rexml/text.rb
index 9804aa710b..8058157605 100644
--- a/lib/rexml/text.rb
+++ b/lib/rexml/text.rb
@@ -308,37 +308,24 @@ module REXML
# Unescapes all possible entities
def Text::unnormalize( string, doctype=nil, filter=nil, illegal=nil )
- rv = string.clone
- rv.gsub!( /\r\n?/, "\n" )
- matches = rv.scan( REFERENCE )
- return rv if matches.size == 0
- rv.gsub!( NUMERICENTITY ) {|m|
- m=$1
- m = "0#{m}" if m[0] == ?x
- [Integer(m)].pack('U*')
- }
- matches.collect!{|x|x[0]}.compact!
- if matches.size > 0
- if doctype
- matches.each do |entity_reference|
- unless filter and filter.include?(entity_reference)
- entity_value = doctype.entity( entity_reference )
- re = /&#{entity_reference};/
- rv.gsub!( re, entity_value ) if entity_value
- end
+ string.gsub( /\r\n?/, "\n" ).gsub( REFERENCE ) { |ref|
+ if ref[1] == ?#
+ if ref[2] == ?x
+ [ref[3...-1].to_i(16)].pack('U*')
+ else
+ [ref[2...-1].to_i].pack('U*')
end
+ elsif ref == '&amp;'
+ '&'
+ elsif filter and filter.include?( ref[1...-1] )
+ ref
+ elsif doctype
+ doctype.entity( ref[1...-1] ) or ref
else
- matches.each do |entity_reference|
- unless filter and filter.include?(entity_reference)
- entity_value = DocType::DEFAULT_ENTITIES[ entity_reference ]
- re = /&#{entity_reference};/
- rv.gsub!( re, entity_value.value ) if entity_value
- end
- end
+ entity_value = DocType::DEFAULT_ENTITIES[ ref[1...-1] ]
+ entity_value ? entity_value.value : ref
end
- rv.gsub!( /&amp;/, '&' )
- end
- rv
+ }
end
end
end