[前][次][番号順一覧][スレッド一覧]

ruby-changes:17432

From: naruse <ko1@a...>
Date: Mon, 11 Oct 2010 07:00:41 +0900 (JST)
Subject: [ruby-changes:17432] Ruby:r29437 (trunk): * ext/stringio/stringio.c (strio_set_encoding):

naruse	2010-10-11 06:54:22 +0900 (Mon, 11 Oct 2010)

  New Revision: 29437

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29437

  Log:
    * 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]

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/ext/stringio/stringio.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29436)
+++ ChangeLog	(revision 29437)
@@ -1,3 +1,9 @@
+Mon Oct 11 06:38:27 2010  NARUSE, Yui  <naruse@r...>
+
+	* 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@r...>
 
 	* io.c (rb_io_set_encoding): use rb_funcall2 when the io is not
@@ -130,9 +136,10 @@
 	* 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@y...>
+Sun Oct  3 20:36:37 2010  Akio Tajima (arton)  <artonx@y...>
 
-	* 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@r...>
 
Index: ext/stringio/stringio.c
===================================================================
--- ext/stringio/stringio.c	(revision 29436)
+++ ext/stringio/stringio.c	(revision 29437)
@@ -1365,17 +1365,29 @@
 
 /*
  *  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 @@
 
     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);
 }
Index: NEWS
===================================================================
--- NEWS	(revision 29436)
+++ NEWS	(revision 29437)
@@ -60,6 +60,10 @@
     * 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?

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]