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

ruby-changes:23077

From: naruse <ko1@a...>
Date: Sun, 25 Mar 2012 18:20:15 +0900 (JST)
Subject: [ruby-changes:23077] naruse:r35127 (trunk): * string.c (tr_setup_table): fix multiple non latin argument for

naruse	2012-03-25 18:20:04 +0900 (Sun, 25 Mar 2012)

  New Revision: 35127

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

  Log:
    * string.c (tr_setup_table): fix multiple non latin argument for
      non latin (over 256 characters) tr-like methods.
      [ruby-core:43371] [Bug #6167]

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_string.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35126)
+++ ChangeLog	(revision 35127)
@@ -1,3 +1,9 @@
+Sun Mar 25 18:13:14 2012  NARUSE, Yui  <naruse@r...>
+
+	* string.c (tr_setup_table): fix multiple non latin argument for
+	  non latin (over 256 characters) tr-like methods.
+	  [ruby-core:43371] [Bug #6167]
+
 Sun Mar 25 00:46:06 2012  Shugo Maeda  <shugo@r...>
 
 	* enumerator (lazy_initialize): set the instance variable "receiver"
Index: string.c
===================================================================
--- string.c	(revision 35126)
+++ string.c	(revision 35127)
@@ -5332,18 +5332,19 @@
 	else {
 	    VALUE key = UINT2NUM(c);
 
-	    if (!table) {
-		table = rb_hash_new();
+	    if (!table && (first || *tablep || stable[256])) {
 		if (cflag) {
 		    ptable = *ctablep;
+		    table = ptable ? ptable : rb_hash_new();
 		    *ctablep = table;
 		}
 		else {
+		    table = rb_hash_new();
 		    ptable = *tablep;
 		    *tablep = table;
 		}
 	    }
-	    if (!ptable || !NIL_P(rb_hash_aref(ptable, key))) {
+	    if (table && (!ptable || (cflag ^ !NIL_P(rb_hash_aref(ptable, key))))) {
 		rb_hash_aset(table, key, Qtrue);
 	    }
 	}
@@ -5351,6 +5352,9 @@
     for (i=0; i<256; i++) {
 	stable[i] = stable[i] && buf[i];
     }
+    if (!table && !cflag) {
+	*tablep = 0;
+    }
 }
 
 
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 35126)
+++ test/ruby/test_string.rb	(revision 35127)
@@ -483,8 +483,15 @@
     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(1, "abc\u{3042 3044 3046}".count("\u3042"))
     assert_equal(5, "abc\u{3042 3044 3046}".count("^\u3042"))
     assert_equal(2, "abc\u{3042 3044 3046}".count("a-z", "^a"))
+    assert_equal(0, "abc\u{3042 3044 3046}".count("a", "\u3042"))
+    assert_equal(0, "abc\u{3042 3044 3046}".count("\u3042", "a"))
+    assert_equal(0, "abc\u{3042 3044 3046}".count("\u3042", "\u3044"))
+    assert_equal(4, "abc\u{3042 3044 3046}".count("^a", "^\u3044"))
+    assert_equal(4, "abc\u{3042 3044 3046}".count("^\u3044", "^a"))
+    assert_equal(4, "abc\u{3042 3044 3046}".count("^\u3042", "^\u3044"))
 
     assert_raise(ArgumentError) { "foo".count }
   end

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

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