summaryrefslogtreecommitdiff
path: root/lib/rdoc
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-26 03:22:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-26 03:22:09 +0000
commit8eee0060f563ebf3d35d91d560944d4dfe648eb0 (patch)
tree4a9c2d5a05f3bd651f27cd0f2c46cb275e60e148 /lib/rdoc
parente0b7af69b461773c66ebfef29e2303f13b111d13 (diff)
* lib/yaml/rubytypes.rb (String#is_binary_data?): TAB would be
usually considered to be included in text data. * lib/rdoc/parser.rb (RDoc::Parser.binary?): blksize may be nil and is irrelevant to whether a file is binary. copied from above since TAB and newlines would be usually considered to be included in text data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/parser.rb12
1 files changed, 3 insertions, 9 deletions
diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb
index 275d3cc8f9..bb7e0c7d81 100644
--- a/lib/rdoc/parser.rb
+++ b/lib/rdoc/parser.rb
@@ -63,17 +63,11 @@ class RDoc::Parser
end
##
- # Shamelessly stolen from the ptools gem (since RDoc cannot depend on
- # the gem).
+ # Return _true_ if the +file+ seems like binary.
def self.binary?(file)
- s = (File.read(file, File.stat(file).blksize, 0, :mode => "rb") || "").split(//)
-
- if s.size > 0 then
- ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
- else
- false
- end
+ s = File.read(file, 1024)
+ s.count("^ -~\t\r\n").fdiv(s.size) > 0.3 || s.index("\x00") unless s.empty?
end
private_class_method :binary?