aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--NEWS4
-rw-r--r--ext/stringio/stringio.c22
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 <naruse@ruby-lang.org>
+
+ * 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 <naruse@ruby-lang.org>
* 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 <s.wanabe@gmail.com>
* 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) <artonx@yahoo.co.jp>
+Sun Oct 3 20:36:37 2010 Akio Tajima (arton) <artonx@yahoo.co.jp>
- * 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 <nobu@ruby-lang.org>
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 <i>ext_enc</i>.
+ * Use the default external encoding if <i>ext_enc</i> is nil.
+ * 2nd argument <i>int_enc</i> and optional hash <i>opt</i> 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);
}