Google

def Text::unnormalize( string, doctype=nil, illegal=nil ) rv = string.clone rv.gsub!( /\r\n?/, "\n" ) matches = rv.scan REFERENCE return rv if matches.size == 0 rv.gsub!( /&#0*((?:\d+)|(?:x[a-f0-9]+));/ ) {|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| entity_value = doctype.entity( entity_reference ) rv.gsub!( /&#{entity_reference};/, entity_value ) if entity_value end else matches.each do |entity_reference| entity_value = DocType::DEFAULT_ENTITIES[ entity_reference ] rv.gsub!( /&#{entity_reference};/, entity_value.value ) if entity_value end end rv.gsub!( /&/, '&' ) end rv end