1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2009-03-26 03:22:09 +00:00
parent e0b7af69b4
commit 8eee0060f5
3 changed files with 14 additions and 10 deletions

View file

@ -1,3 +1,13 @@
Thu Mar 26 12:22:06 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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.
Thu Mar 26 11:33:13 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/rdoc/ri/paths.rb (RDoc::RI::Paths): considers

View file

@ -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?

View file

@ -143,7 +143,7 @@ class String
to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
end
def is_binary_data?
( self.count( "^ -~", "^\r\n" ).fdiv(self.size) > 0.3 || self.index( "\x00" ) ) unless empty?
self.count("^ -~\t\r\n").fdiv(self.size) > 0.3 || self.index("\x00") unless self.empty?
end
def String.yaml_new( klass, tag, val )
val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary"