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

ruby-changes:17564

From: yugui <ko1@a...>
Date: Sat, 23 Oct 2010 19:12:56 +0900 (JST)
Subject: [ruby-changes:17564] Ruby:r29569 (ruby_1_9_2): merges r29146 and r29148 from trunk into ruby_1_9_2.

yugui	2010-10-23 19:02:41 +0900 (Sat, 23 Oct 2010)

  New Revision: 29569

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

  Log:
    merges r29146 and r29148 from trunk into ruby_1_9_2.
    --
    * string.c (tr_setup_table): initialize negating table when
      negating string is given. [ruby-core:31851]
    
    * string.c (tr_find): add a sentence for the time when
      target characters include negating one.
    
    * string.c (rb_str_count): move definition.
    --
    * 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:
    branches/ruby_1_9_2/ChangeLog
    branches/ruby_1_9_2/ext/psych/lib/psych/visitors/yaml_tree.rb
    branches/ruby_1_9_2/ext/syck/lib/syck/rubytypes.rb
    branches/ruby_1_9_2/lib/rdoc/parser.rb
    branches/ruby_1_9_2/string.c
    branches/ruby_1_9_2/test/ruby/test_string.rb
    branches/ruby_1_9_2/version.h

Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 29568)
+++ ruby_1_9_2/ChangeLog	(revision 29569)
@@ -1,3 +1,22 @@
+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 15:00:13 2010  NARUSE, Yui  <naruse@r...>
+
+	* string.c (tr_setup_table): initialize negating table when
+	  negating string is given. [ruby-core:31851]
+
+	* string.c (tr_find): add a sentence for the time when
+	  target characters include negating one.
+
+	* string.c (rb_str_count): move definition.
+
 Sun Aug 29 23:54:10 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/rdoc/parser/ruby.rb (RDoc#parse_call_parameters): don't
Index: ruby_1_9_2/string.c
===================================================================
--- ruby_1_9_2/string.c	(revision 29568)
+++ ruby_1_9_2/string.c	(revision 29569)
@@ -5035,7 +5035,16 @@
     if (RSTRING_LEN(str) > 1 && rb_enc_ascget(tr.p, tr.pend, &l, enc) == '^') {
 	cflag = 1;
 	tr.p += l;
+
+	table = rb_hash_new();
+	ptable = *ctablep;
+	*ctablep = table;
     }
+    else {
+	table = rb_hash_new();
+	ptable = *tablep;
+	*tablep = table;
+    }
     if (first) {
 	for (i=0; i<256; i++) {
 	    stable[i] = 1;
@@ -5054,14 +5063,8 @@
 
 	    if (!table) {
 		table = rb_hash_new();
-		if (cflag) {
-		    ptable = *ctablep;
-		    *ctablep = table;
-		}
-		else {
-		    ptable = *tablep;
-		    *tablep = table;
-		}
+		ptable = *tablep;
+		*tablep = table;
 	    }
 	    if (!ptable || !NIL_P(rb_hash_aref(ptable, key))) {
 		rb_hash_aset(table, key, Qtrue);
@@ -5083,11 +5086,15 @@
     else {
 	VALUE v = UINT2NUM(c);
 
-	if (del && !NIL_P(rb_hash_lookup(del, v))) {
-	    if (!nodel || NIL_P(rb_hash_lookup(nodel, v))) {
+	if (del) {
+	    if (!NIL_P(rb_hash_lookup(del, v)) &&
+		    (!nodel || NIL_P(rb_hash_lookup(nodel, v)))) {
 		return TRUE;
 	    }
 	}
+	else if (nodel && NIL_P(rb_hash_lookup(nodel, v))) {
+	    return TRUE;
+	}
 	return FALSE;
     }
 }
@@ -5388,16 +5395,15 @@
     i = 0;
     while (s < send) {
 	unsigned int c;
-	int clen;
 
 	if (ascompat && (c = *(unsigned char*)s) < 0x80) {
-	    clen = 1;
 	    if (table[c]) {
 		i++;
 	    }
 	    s++;
 	}
 	else {
+	    int clen;
 	    c = rb_enc_codepoint_len(s, send, &clen, enc);
 	    if (tr_find(c, table, del, nodel)) {
 		i++;
Index: ruby_1_9_2/lib/rdoc/parser.rb
===================================================================
--- ruby_1_9_2/lib/rdoc/parser.rb	(revision 29568)
+++ ruby_1_9_2/lib/rdoc/parser.rb	(revision 29569)
@@ -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: ruby_1_9_2/ext/psych/lib/psych/visitors/yaml_tree.rb
===================================================================
--- ruby_1_9_2/ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 29568)
+++ ruby_1_9_2/ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 29569)
@@ -180,7 +180,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: ruby_1_9_2/ext/syck/lib/syck/rubytypes.rb
===================================================================
--- ruby_1_9_2/ext/syck/lib/syck/rubytypes.rb	(revision 29568)
+++ ruby_1_9_2/ext/syck/lib/syck/rubytypes.rb	(revision 29569)
@@ -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: ruby_1_9_2/version.h
===================================================================
--- ruby_1_9_2/version.h	(revision 29568)
+++ ruby_1_9_2/version.h	(revision 29569)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.2"
-#define RUBY_PATCHLEVEL 22
+#define RUBY_PATCHLEVEL 23
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 9
 #define RUBY_VERSION_TEENY 1
Index: ruby_1_9_2/test/ruby/test_string.rb
===================================================================
--- ruby_1_9_2/test/ruby/test_string.rb	(revision 29568)
+++ ruby_1_9_2/test/ruby/test_string.rb	(revision 29569)
@@ -479,6 +479,8 @@
     assert_equal(4, a.count(S("hello"), S("^l")))
     assert_equal(4, a.count(S("ej-m")))
     assert_equal(0, S("y").count(S("a\\-z")))
+    assert_equal(5, "abc\u{3042 3044 3046}".count("^a"))
+    assert_equal(5, "abc\u{3042 3044 3046}".count("^\u3042"))
 
     assert_raise(ArgumentError) { "foo".count }
   end
@@ -498,6 +500,10 @@
     assert_equal(true, "a\u0101".delete("\u0101").ascii_only?)
     assert_equal(true, "a\u3041".delete("\u3041").ascii_only?)
     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
 
   def test_delete!

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

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