ruby-changes:18532
From: yugui <ko1@a...>
Date: Sun, 16 Jan 2011 15:30:33 +0900 (JST)
Subject: [ruby-changes:18532] Ruby:r30555 (ruby_1_9_2): merges r30349 from trunk into ruby_1_9_2.
yugui 2011-01-16 15:30:14 +0900 (Sun, 16 Jan 2011) New Revision: 30555 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30555 Log: merges r30349 from trunk into ruby_1_9_2. -- * io.c (rb_io_extract_encoding_option): accept Encoding object as encoding: optional argument. [ruby-dev:42884] Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/io.c branches/ruby_1_9_2/test/ruby/test_io_m17n.rb branches/ruby_1_9_2/version.h Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 30554) +++ ruby_1_9_2/ChangeLog (revision 30555) @@ -1,3 +1,8 @@ +Sat Dec 25 14:27:09 2010 Nobuyoshi Nakada <nobu@r...> + + * io.c (rb_io_extract_encoding_option): accept Encoding object as + encoding: optional argument. [ruby-dev:42884] + Sat Dec 25 15:08:08 2010 KOSAKI Motohiro <kosaki.motohiro@g...> * ext/pty/pty.c (chfunc): Added rb_thread_atfork_before_exec(). Index: ruby_1_9_2/io.c =================================================================== --- ruby_1_9_2/io.c (revision 30554) +++ ruby_1_9_2/io.c (revision 30555) @@ -4325,9 +4325,12 @@ if (v != Qundef) intenc = v; } if ((extenc != Qundef || intenc != Qundef) && !NIL_P(encoding)) { - rb_warn("Ignoring encoding parameter '%s': %s_encoding is used", - StringValueCStr(encoding), - extenc == Qundef ? "internal" : "external"); + if (!NIL_P(ruby_verbose)) { + int idx = rb_to_encoding_index(encoding); + rb_warn("Ignoring encoding parameter '%s': %s_encoding is used", + idx < 0 ? StringValueCStr(encoding) : rb_enc_name(rb_enc_from_index(idx)), + extenc == Qundef ? "internal" : "external"); + } encoding = Qnil; } if (extenc != Qundef && !NIL_P(extenc)) { @@ -4358,7 +4361,12 @@ } if (!NIL_P(encoding)) { extracted = 1; - parse_mode_enc(StringValueCStr(encoding), enc_p, enc2_p, fmode_p); + if (!NIL_P(tmp = rb_check_string_type(encoding))) { + parse_mode_enc(StringValueCStr(tmp), enc_p, enc2_p, fmode_p); + } + else { + rb_io_ext_int_to_encs(rb_to_encoding(encoding), NULL, enc_p, enc2_p); + } } else if (extenc != Qundef || intenc != Qundef) { extracted = 1; Index: ruby_1_9_2/version.h =================================================================== --- ruby_1_9_2/version.h (revision 30554) +++ ruby_1_9_2/version.h (revision 30555) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 137 +#define RUBY_PATCHLEVEL 138 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_2/test/ruby/test_io_m17n.rb =================================================================== --- ruby_1_9_2/test/ruby/test_io_m17n.rb (revision 30554) +++ ruby_1_9_2/test/ruby/test_io_m17n.rb (revision 30555) @@ -114,9 +114,29 @@ } end - def test_open_r_enc_in_opt2 + def test_open_r_encname_in_opt with_tmpdir { generate_file('tmp', "") + open("tmp", "r", encoding: Encoding::EUC_JP) {|f| + assert_equal(Encoding::EUC_JP, f.external_encoding) + assert_equal(nil, f.internal_encoding) + } + } + end + + def test_open_r_ext_enc_in_opt + with_tmpdir { + generate_file('tmp', "") + open("tmp", "r", external_encoding: Encoding::EUC_JP) {|f| + assert_equal(Encoding::EUC_JP, f.external_encoding) + assert_equal(nil, f.internal_encoding) + } + } + end + + def test_open_r_ext_encname_in_opt + with_tmpdir { + generate_file('tmp', "") open("tmp", "r", external_encoding: "euc-jp") {|f| assert_equal(Encoding::EUC_JP, f.external_encoding) assert_equal(nil, f.internal_encoding) @@ -127,6 +147,16 @@ def test_open_r_enc_enc with_tmpdir { generate_file('tmp', "") + open("tmp", "r", external_encoding: Encoding::EUC_JP, internal_encoding: Encoding::UTF_8) {|f| + assert_equal(Encoding::EUC_JP, f.external_encoding) + assert_equal(Encoding::UTF_8, f.internal_encoding) + } + } + end + + def test_open_r_encname_encname + with_tmpdir { + generate_file('tmp', "") open("tmp", "r:euc-jp:utf-8") {|f| assert_equal(Encoding::EUC_JP, f.external_encoding) assert_equal(Encoding::UTF_8, f.internal_encoding) @@ -134,7 +164,7 @@ } end - def test_open_r_enc_enc_in_opt + def test_open_r_encname_encname_in_opt with_tmpdir { generate_file('tmp', "") open("tmp", "r", encoding: "euc-jp:utf-8") {|f| @@ -144,9 +174,19 @@ } end - def test_open_r_enc_enc_in_opt2 + def test_open_r_enc_enc_in_opt with_tmpdir { generate_file('tmp', "") + open("tmp", "r", external_encoding: Encoding::EUC_JP, internal_encoding: Encoding::UTF_8) {|f| + assert_equal(Encoding::EUC_JP, f.external_encoding) + assert_equal(Encoding::UTF_8, f.internal_encoding) + } + } + end + + def test_open_r_encname_encname_in_opt + with_tmpdir { + generate_file('tmp', "") open("tmp", "r", external_encoding: "euc-jp", internal_encoding: "utf-8") {|f| assert_equal(Encoding::EUC_JP, f.external_encoding) assert_equal(Encoding::UTF_8, f.internal_encoding) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/