From 47cb5a93e50c26114434dddb3008e5e4912a76f5 Mon Sep 17 00:00:00 2001 From: naruse Date: Sun, 10 Oct 2010 21:54:22 +0000 Subject: [PATCH] * ext/stringio/stringio.c (strio_set_encoding): StringIO#set_encoding can get 2nd argument and optional hash for API compatibility to IO. [ruby-dev:42356] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++-- NEWS | 4 ++++ ext/stringio/stringio.c | 22 +++++++++++++++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 518cf6b9ed..4f39553386 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Oct 11 06:38:27 2010 NARUSE, Yui + + * ext/stringio/stringio.c (strio_set_encoding): + StringIO#set_encoding can get 2nd argument and optional hash + for API compatibility to IO. [ruby-dev:42356] + Mon Oct 11 06:11:30 2010 NARUSE, Yui * io.c (rb_io_set_encoding): use rb_funcall2 when the io is not @@ -130,9 +136,10 @@ Mon Oct 4 00:01:53 2010 wanabe * win32/mkexports.rb: no longer use 'mingw64'. a patch from Luis Lavena at [ruby-core:32678]. -Sun Oct 3 20:36:37 2010 Akio Tajima (arton) +Sun Oct 3 20:36:37 2010 Akio Tajima (arton) - * test/win32ole/test_folderitem2_invokeverb.rb: Change creating shortcut verb to 'Link' [Bug #3339] + * test/win32ole/test_folderitem2_invokeverb.rb: Change creating + shortcut verb to 'Link' [Bug #3339] Sun Oct 3 19:44:23 2010 Nobuyoshi Nakada diff --git a/NEWS b/NEWS index f1acea776b..d6c7e39dfa 100644 --- a/NEWS +++ b/NEWS @@ -60,6 +60,10 @@ with all sufficient information, see the ChangeLog file. * URI::Generic#hostname * URI::Generic#hostname= +* stringio + * extended methods: + * StringIO#set_encoding can get 2nd argument and optional hash. + === Compatibility issues (excluding feature bug fixes) * Kernel#respond_to? diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 4628a357dd..75f8cd7f6d 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1365,17 +1365,29 @@ strio_internal_encoding(VALUE self) /* * call-seq: - * strio.set_encoding(ext_enc) => strio + * strio.set_encoding(ext_enc, [int_enc[, opt]]) => strio * - * Tagged with the encoding specified. + * Specify the encoding of the StringIO as ext_enc. + * Use the default external encoding if ext_enc is nil. + * 2nd argument int_enc and optional hash opt argument + * are ignored; they are for API compatibility to IO. */ static VALUE -strio_set_encoding(VALUE self, VALUE ext_enc) +strio_set_encoding(int argc, VALUE *argv, VALUE self) { rb_encoding* enc; VALUE str = StringIO(self)->string; - enc = rb_to_encoding(ext_enc); + VALUE ext_enc, int_enc, opt; + + argc = rb_scan_args(argc, argv, "11:", &ext_enc, &int_enc, &opt); + + if (NIL_P(ext_enc)) { + enc = rb_default_external_encoding(); + } + else { + enc = rb_to_encoding(ext_enc); + } rb_enc_associate(str, enc); return self; } @@ -1462,5 +1474,5 @@ Init_stringio() rb_define_method(StringIO, "external_encoding", strio_external_encoding, 0); rb_define_method(StringIO, "internal_encoding", strio_internal_encoding, 0); - rb_define_method(StringIO, "set_encoding", strio_set_encoding, 1); + rb_define_method(StringIO, "set_encoding", strio_set_encoding, -1); }