summaryrefslogtreecommitdiff
path: root/ext/stringio
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-10 21:54:22 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-10 21:54:22 +0000
commit47cb5a93e50c26114434dddb3008e5e4912a76f5 (patch)
treeeca8fb2902af5a7befb9e5f16894ab8ac94ae779 /ext/stringio
parent6221ba109c9ae7ce8f752f1d35703c3f0cb07c0f (diff)
* 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
Diffstat (limited to 'ext/stringio')
-rw-r--r--ext/stringio/stringio.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 4628a35..75f8cd7 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);
}