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

ruby-changes:8508

From: yugui <ko1@a...>
Date: Thu, 30 Oct 2008 01:29:41 +0900 (JST)
Subject: [ruby-changes:8508] Ruby:r20042 (ruby_1_9_1): merged r20021 and r20022 from trunk into ruby_1_9_1.

yugui	2008-10-30 01:27:00 +0900 (Thu, 30 Oct 2008)

  New Revision: 20042

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

  Log:
    merged r20021 and r20022 from trunk into ruby_1_9_1.
        * pack.c (pack_pack): set encoding from packing string and UTF-8 for
          "U".  [ruby-core:19590]
        * test/ruby/test_array.rb (test_pack): use utf-8.
    
        * test/ruby/test_pack.rb (test_pack_U): ditto.

  Modified files:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/pack.c
    branches/ruby_1_9_1/test/ruby/test_array.rb
    branches/ruby_1_9_1/test/ruby/test_pack.rb

Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 20041)
+++ ruby_1_9_1/ChangeLog	(revision 20042)
@@ -18,6 +18,11 @@
 	  test/webrick/test_server.rb, test/webrick/test_filehandler.rb: use
 	  webrick log as an assertion message.
 
+Wed Oct 29 16:41:17 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* pack.c (pack_pack): set encoding from packing string and UTF-8 for
+	  "U".  [ruby-core:19590]
+
 Wed Oct  29 15:50:00 2008  TAKANO Mitsuhiro (takano32)  <tak@n...>
 
 	* complex.c (imp1, imp2): should declare type.
Index: ruby_1_9_1/pack.c
===================================================================
--- ruby_1_9_1/pack.c	(revision 20041)
+++ ruby_1_9_1/pack.c	(revision 20042)
@@ -10,6 +10,7 @@
 **********************************************************************/
 
 #include "ruby/ruby.h"
+#include "ruby/encoding.h"
 #include <sys/types.h>
 #include <ctype.h>
 #include <errno.h>
@@ -443,6 +444,7 @@
     char type;
     long items, len, idx, plen;
     const char *ptr;
+    rb_encoding *enc;
 #ifdef NATINT_PACK
     int natint;		/* native integer */
 #endif
@@ -517,6 +519,8 @@
 		ptr = RSTRING_PTR(from);
 		plen = RSTRING_LEN(from);
 		OBJ_INFECT(res, from);
+		enc = rb_enc_compatible(res, from);
+		rb_enc_associate(res, enc);
 	    }
 
 	    if (p[-1] == '*')
@@ -865,6 +869,8 @@
 	    break;
 
 	  case 'U':		/* Unicode character */
+	    enc = rb_enc_compatible(res, rb_enc_from_encoding(rb_utf8_encoding()));
+	    rb_enc_associate(res, enc);
 	    while (len-- > 0) {
 		SIGNED_VALUE l;
 		char buf[8];
Index: ruby_1_9_1/test/ruby/test_pack.rb
===================================================================
--- ruby_1_9_1/test/ruby/test_pack.rb	(revision 20041)
+++ ruby_1_9_1/test/ruby/test_pack.rb	(revision 20042)
@@ -51,9 +51,9 @@
     assert_raise(RangeError) { [-0x40000000].pack("U") }
     assert_raise(RangeError) { [-1].pack("U") }
     assert_equal "\000", [0].pack("U")
-    assert_equal "\374\277\277\277\277\277", [0x3fffffff].pack("U")
-    assert_equal "\375\200\200\200\200\200", [0x40000000].pack("U")
-    assert_equal "\375\277\277\277\277\277", [0x7fffffff].pack("U")
+    assert_equal "\374\277\277\277\277\277".force_encoding(Encoding::UTF_8), [0x3fffffff].pack("U")
+    assert_equal "\375\200\200\200\200\200".force_encoding(Encoding::UTF_8), [0x40000000].pack("U")
+    assert_equal "\375\277\277\277\277\277".force_encoding(Encoding::UTF_8), [0x7fffffff].pack("U")
     assert_raise(RangeError) { [0x80000000].pack("U") }
     assert_raise(RangeError) { [0x100000000].pack("U") }
   end
Index: ruby_1_9_1/test/ruby/test_array.rb
===================================================================
--- ruby_1_9_1/test/ruby/test_array.rb	(revision 20041)
+++ ruby_1_9_1/test/ruby/test_array.rb	(revision 20042)
@@ -888,7 +888,7 @@
     assert_equal("aGVsbG8K\n",  @cls["hello\n"].pack("m"))
     assert_equal(",:&5L;&\\*:&5L;&\\*\n",  @cls["hello\nhello\n"].pack("u"))
 
-    assert_equal("\xc2\xa9B\xe2\x89\xa0", @cls[0xa9, 0x42, 0x2260].pack("U*"))
+    assert_equal("\u{a9 42 2260}", @cls[0xa9, 0x42, 0x2260].pack("U*"))
 
 
     format = "c2x5CCxsdils_l_a6";

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

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