ruby-changes:17443
From: naruse <ko1@a...>
Date: Tue, 12 Oct 2010 15:37:34 +0900 (JST)
Subject: [ruby-changes:17443] Ruby:r29448 (trunk): * io.c (rb_io_ungetc): use unsigned int for GB18030.
naruse 2010-10-12 15:37:27 +0900 (Tue, 12 Oct 2010) New Revision: 29448 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29448 Log: * io.c (rb_io_ungetc): use unsigned int for GB18030. Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io_m17n.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 29447) +++ ChangeLog (revision 29448) @@ -1,3 +1,7 @@ +Tue Oct 12 15:36:09 2010 NARUSE, Yui <naruse@r...> + + * io.c (rb_io_ungetc): use unsigned int for GB18030. + Tue Oct 12 15:14:21 2010 NARUSE, Yui <naruse@r...> * io.c (rb_io_putc): support multibyte characters. Index: io.c =================================================================== --- io.c (revision 29447) +++ io.c (revision 29448) @@ -3229,12 +3229,13 @@ rb_io_check_char_readable(fptr); if (NIL_P(c)) return Qnil; if (FIXNUM_P(c)) { - int cc = FIX2INT(c); - rb_encoding *enc = io_read_encoding(fptr); - char buf[16]; - - c = rb_str_new(buf, rb_enc_mbcput(cc, buf, enc)); + c = rb_enc_uint_chr(FIX2UINT(c), io_read_encoding(fptr)); } +#if SIZEOF_LONG > SIZEOF_INT + else if (TYPE(c) == T_BIGNUM) { + c = rb_enc_uint_chr(NUM2UINT(c), io_read_encoding(fptr)); + } +#endif else { SafeStringValue(c); } Index: test/ruby/test_io_m17n.rb =================================================================== --- test/ruby/test_io_m17n.rb (revision 29447) +++ test/ruby/test_io_m17n.rb (revision 29448) @@ -418,6 +418,30 @@ } end + def test_ungetc_int + with_tmpdir { + generate_file('tmp', "A") + s = open("tmp", "r:GB18030") {|f| + f.ungetc(0x8431A439) + f.read + } + assert_equal(Encoding::GB18030, s.encoding) + assert_str_equal(0x8431A439.chr("GB18030")+"A", s) + } + end + + def test_ungetc_str + with_tmpdir { + generate_file('tmp', "A") + s = open("tmp", "r:GB18030") {|f| + f.ungetc(0x8431A439.chr("GB18030")) + f.read + } + assert_equal(Encoding::GB18030, s.encoding) + assert_str_equal(0x8431A439.chr("GB18030")+"A", s) + } + end + def test_ungetc_stateful_conversion with_tmpdir { src = "before \e$B\x23\x30\x23\x31\e(B after".force_encoding("iso-2022-jp") -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/