From ea7a527a2ae7024a5cf2885dee8f7a5c21fedd5d Mon Sep 17 00:00:00 2001 From: ser Date: Tue, 10 Jun 2003 01:31:01 +0000 Subject: Initial revision git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rexml/encoding.rb | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 lib/rexml/encoding.rb (limited to 'lib/rexml/encoding.rb') diff --git a/lib/rexml/encoding.rb b/lib/rexml/encoding.rb new file mode 100644 index 0000000000..3d7dcd6260 --- /dev/null +++ b/lib/rexml/encoding.rb @@ -0,0 +1,62 @@ +module REXML + module Encoding + @@uconv_available = false + + ENCODING_CLAIMS = { } + + def Encoding.claim( encoding_str, match=nil ) + if match + ENCODING_CLAIMS[ match ] = encoding_str + else + ENCODING_CLAIMS[ /^\s* Encoding name + attr_reader :encoding + def encoding=( enc ) + enc = UTF_8 unless enc + @encoding = enc.upcase + require "rexml/encodings/#@encoding" unless @encoding == UTF_8 + end + + def check_encoding str + rv = ENCODING_CLAIMS.find{|k,v| str =~ k } + # Raise an exception if there is a declared encoding and we don't + # recognize it + unless rv + if str =~ /^\s* 0 + encodings |= Dir[ File.join(incl_dir, 'rexml', 'encodings', '*_decl.rb') ] + end + encodings.collect!{ |f| File.basename(f) } + encodings.uniq! + end + encodings.each { |enc| require "rexml/encodings/#{enc}" } + end +end -- cgit v1.2.3