[前][次][番号順一覧][スレッド一覧]

ruby-changes:17150

From: naruse <ko1@a...>
Date: Tue, 31 Aug 2010 04:46:07 +0900 (JST)
Subject: [ruby-changes:17150] Ruby:r29148 (trunk): * string.c (tr_setup_table): fix bug in r29146.

naruse	2010-08-31 04:45:30 +0900 (Tue, 31 Aug 2010)

  New Revision: 29148

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29148

  Log:
    * string.c (tr_setup_table): fix bug in r29146.
      Initialize table even if cflag is 0; tr_find see whether
      del is empty or not.
    
    * string.c (tr_find): nodel can't be NULL; if NULL, it means
      it is not specified.

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/visitors/yaml_tree.rb
    trunk/ext/syck/lib/syck/rubytypes.rb
    trunk/lib/rdoc/parser.rb
    trunk/string.c
    trunk/test/ruby/test_string.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29147)
+++ ChangeLog	(revision 29148)
@@ -1,3 +1,12 @@
+Tue Aug 31 03:42:14 2010  NARUSE, Yui  <naruse@r...>
+
+	* string.c (tr_setup_table): fix bug in r29146.
+	  Initialize table even if cflag is 0; tr_find see whether
+	  del is empty or not.
+
+	* string.c (tr_find): nodel can't be NULL; if NULL, it means
+	  it is not specified.
+
 Mon Aug 30 21:29:21 2010  Tanaka Akira  <akr@f...>
 
 	* ext/pathname/pathname.c (path_executable_real_p):
Index: string.c
===================================================================
--- string.c	(revision 29147)
+++ string.c	(revision 29148)
@@ -5095,6 +5095,11 @@
 	ptable = *ctablep;
 	*ctablep = table;
     }
+    else {
+	table = rb_hash_new();
+	ptable = *tablep;
+	*tablep = table;
+    }
     if (first) {
 	for (i=0; i<256; i++) {
 	    stable[i] = 1;
@@ -5113,10 +5118,8 @@
 
 	    if (!table) {
 		table = rb_hash_new();
-		if (!cflag) {
-		    ptable = *tablep;
-		    *tablep = table;
-		}
+		ptable = *tablep;
+		*tablep = table;
 	    }
 	    if (!ptable || !NIL_P(rb_hash_aref(ptable, key))) {
 		rb_hash_aset(table, key, Qtrue);
@@ -5144,7 +5147,7 @@
 		return TRUE;
 	    }
 	}
-	else if (!nodel || NIL_P(rb_hash_lookup(nodel, v))) {
+	else if (nodel && NIL_P(rb_hash_lookup(nodel, v))) {
 	    return TRUE;
 	}
 	return FALSE;
Index: lib/rdoc/parser.rb
===================================================================
--- lib/rdoc/parser.rb	(revision 29147)
+++ lib/rdoc/parser.rb	(revision 29148)
@@ -76,9 +76,9 @@
     elsif s.scan(/<%|%>/).length >= 4 || s.index("\x00") then
       true
     elsif 0.respond_to? :fdiv then
-      s.count("^ -~\t\r\n").fdiv(s.size) > 0.3
+      s.count("\x00-\x7F", "^ -~\t\r\n").fdiv(s.size) > 0.3
     else # HACK 1.8.6
-      (s.count("^ -~\t\r\n").to_f / s.size) > 0.3
+      (s.count("\x00-\x7F", "^ -~\t\r\n").to_f / s.size) > 0.3
     end
   end
 
Index: ext/psych/lib/psych/visitors/yaml_tree.rb
===================================================================
--- ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 29147)
+++ ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 29148)
@@ -205,7 +205,7 @@
         quote = false
         style = Nodes::Scalar::ANY
 
-        if o.index("\x00") || o.count("^ -~\t\r\n").fdiv(o.length) > 0.3
+        if o.index("\x00") || o.count("\x00-\x7F", "^ -~\t\r\n").fdiv(o.length) > 0.3
           str   = [o].pack('m').chomp
           tag   = '!binary' # FIXME: change to below when syck is removed
           #tag   = 'tag:yaml.org,2002:binary'
Index: ext/syck/lib/syck/rubytypes.rb
===================================================================
--- ext/syck/lib/syck/rubytypes.rb	(revision 29147)
+++ ext/syck/lib/syck/rubytypes.rb	(revision 29148)
@@ -148,7 +148,7 @@
         to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
     end
     def is_binary_data?
-        self.count("^ -~\t\r\n").fdiv(self.size) > 0.3 || self.index("\x00") unless self.empty?
+        self.count("\x00-\x7F", "^ -~\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"
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 29147)
+++ test/ruby/test_string.rb	(revision 29148)
@@ -502,6 +502,7 @@
     assert_equal(false, "a\u3041\u3042".tr("\u3041", "a").ascii_only?)
 
     assert_equal("a", "abc\u{3042 3044 3046}".delete("^a"))
+    assert_equal("bc\u{3042 3044 3046}", "abc\u{3042 3044 3046}".delete("a"))
     assert_equal("\u3042", "abc\u{3042 3044 3046}".delete("^\u3042"))
   end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]