def Text::normalize( input, doctype=nil )
copy = input.clone
# Doing it like this rather than in a loop improves the speedif doctype
copy.gsub!( EREFERENCE, '&' )
doctype.entities.each_value do |entity|
copy.gsub!( entity.value, "&#{entity.name};" ) if entity.value
endelse
copy.gsub!( EREFERENCE, '&' )
DocType::DEFAULT_ENTITIES.each_value do |entity|
copy.gsub!(entity.value, "&#{entity.name};" )
endend
copy
end