diff options
Diffstat (limited to 'lib/rdoc')
-rw-r--r-- | lib/rdoc/parser.rb | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index 27267f3d81..9cc1485422 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -80,14 +80,14 @@ class RDoc::Parser have_encoding = s.respond_to? :encoding - if have_encoding then - return false if s.encoding != Encoding::ASCII_8BIT and s.valid_encoding? - end - return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00") if have_encoding then - s.force_encoding Encoding.default_external + mode = "r" + s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024. + encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*\([^\s;]+?\)(?:-\*-)?/, 1] + mode = "r:#{encoding}" if encoding + s = File.open(file, mode) {|f| f.gets(nil, 1024)} not s.valid_encoding? else |