ruby-changes:15295
From: nobu <ko1@a...>
Date: Fri, 2 Apr 2010 14:12:49 +0900 (JST)
Subject: [ruby-changes:15295] Ruby:r27180 (trunk): * lib/rdoc/parser.rb (RDoc::Parser.binary?): blksize may be nil
nobu 2010-04-02 14:12:31 +0900 (Fri, 02 Apr 2010) New Revision: 27180 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27180 Log: * lib/rdoc/parser.rb (RDoc::Parser.binary?): blksize may be nil and is irrelevant to whether a file is binary. TAB and newlines would be usually considered to be included in text data. reapplied r23071 and r24297. Modified files: trunk/ChangeLog trunk/lib/rdoc/parser.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 27179) +++ ChangeLog (revision 27180) @@ -1,3 +1,10 @@ +Fri Apr 2 14:12:24 2010 Nobuyoshi Nakada <nobu@r...> + + * lib/rdoc/parser.rb (RDoc::Parser.binary?): blksize may be nil + and is irrelevant to whether a file is binary. TAB and newlines + would be usually considered to be included in text data. + reapplied r23071 and r24297. + Fri Apr 2 13:59:17 2010 Nobuyoshi Nakada <nobu@r...> * lib/rdoc/ri/paths.rb (RDoc::RI::Paths): Gem::Enable has been Index: lib/rdoc/parser.rb =================================================================== --- lib/rdoc/parser.rb (revision 27179) +++ lib/rdoc/parser.rb (revision 27180) @@ -67,7 +67,7 @@ # content that an RDoc parser shouldn't try to consume. def self.binary?(file) - s = File.read(file, File.stat(file).blksize || 1024) || "" + s = File.read(file, 1024) or return false if s[0, 2] == Marshal.dump('')[0, 2] then true @@ -76,10 +76,7 @@ elsif s.scan(/<%|%>/).length >= 4 then true else - # From ptools under the Artistic License 2.0, (c) Daniel Berger. - s = s.split(//) - - ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30 + s.count("^ -~\t\r\n").fdiv(s.size) > 0.3 || s.index("\x00") end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/