mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@20042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2e42037f3d
commit
d23702f1f1
4 changed files with 15 additions and 4 deletions
|
@ -18,6 +18,11 @@ Wed Oct 29 20:45:08 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
|||
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@ruby-lang.org>
|
||||
|
||||
* 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@no32.tk>
|
||||
|
||||
* complex.c (imp1, imp2): should declare type.
|
||||
|
|
6
pack.c
6
pack.c
|
@ -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 @@ pack_pack(VALUE ary, VALUE fmt)
|
|||
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 @@ pack_pack(VALUE ary, VALUE fmt)
|
|||
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 @@ pack_pack(VALUE ary, VALUE fmt)
|
|||
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];
|
||||
|
|
|
@ -888,7 +888,7 @@ class TestArray < Test::Unit::TestCase
|
|||
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";
|
||||
|
|
|
@ -51,9 +51,9 @@ class TestPack < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue