ruby-changes:11446
From: nobu <ko1@a...>
Date: Thu, 26 Mar 2009 12:22:24 +0900 (JST)
Subject: [ruby-changes:11446] Ruby:r23071 (trunk): * lib/yaml/rubytypes.rb (String#is_binary_data?): TAB would be
nobu 2009-03-26 12:22:09 +0900 (Thu, 26 Mar 2009) New Revision: 23071 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23071 Log: * 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. Modified files: trunk/ChangeLog trunk/lib/rdoc/parser.rb trunk/lib/yaml/rubytypes.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 23070) +++ ChangeLog (revision 23071) @@ -1,3 +1,13 @@ +Thu Mar 26 12:22:06 2009 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * lib/rdoc/ri/paths.rb (RDoc::RI::Paths): considers Index: lib/rdoc/parser.rb =================================================================== --- lib/rdoc/parser.rb (revision 23070) +++ lib/rdoc/parser.rb (revision 23071) @@ -63,17 +63,11 @@ 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? Index: lib/yaml/rubytypes.rb =================================================================== --- lib/yaml/rubytypes.rb (revision 23070) +++ lib/yaml/rubytypes.rb (revision 23071) @@ -143,7 +143,7 @@ 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" -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/