summaryrefslogtreecommitdiff
path: root/lib/rdoc/encoding.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-02-07 07:07:12 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-02-07 07:07:12 +0000
commit60f2c9cf5bea6dd99fac50c460eab4809cc30b01 (patch)
treeab40b4f7be3ff6d9fc8aede6b90e1aa9dded0aff /lib/rdoc/encoding.rb
parentca9f7009db8aea70af3dd58cb6c7de0010844d22 (diff)
Upgrade to RDoc 3.5.3. Fixes [Bug #4376]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30815 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/encoding.rb')
-rw-r--r--lib/rdoc/encoding.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/rdoc/encoding.rb b/lib/rdoc/encoding.rb
index 8483aabbc6..cfe1ba7725 100644
--- a/lib/rdoc/encoding.rb
+++ b/lib/rdoc/encoding.rb
@@ -12,8 +12,11 @@ module RDoc::Encoding
#
# The content will be converted to the +encoding+. If the file cannot be
# converted a warning will be printed and nil will be returned.
+ #
+ # If +force_transcode+ is true the document will be transcoded and any
+ # unknown character in the target encoding will be replaced with '?'
- def self.read_file filename, encoding
+ def self.read_file filename, encoding, force_transcode = false
content = open filename, "rb" do |f| f.read end
utf8 = content.sub!(/\A\xef\xbb\xbf/, '')
@@ -50,8 +53,14 @@ module RDoc::Encoding
warn "unknown encoding name \"#{$1}\" for #{filename}, skipping"
nil
rescue Encoding::UndefinedConversionError => e
- warn "unable to convert #{e.message} for #{filename}, skipping"
- nil
+ if force_transcode then
+ content.force_encoding orig_encoding
+ content.encode! encoding, :undef => :replace, :replace => '?'
+ content
+ else
+ warn "unable to convert #{e.message} for #{filename}, skipping"
+ nil
+ end
rescue Errno::EISDIR, Errno::ENOENT
nil
end