diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | ext/stringio/stringio.c | 31 |
2 files changed, 39 insertions, 0 deletions
@@ -1,3 +1,11 @@ +Sat Oct 4 18:47:22 2008 NARUSE, Yui <naruse@ruby-lang.org> + + * ext/stringio/stringio.c (strio_external_encoding): defined. + + * ext/stringio/stringio.c (strio_internal_encoding): defined. + + * ext/stringio/stringio.c (Init_stringio): define above. + Sat Oct 4 15:52:17 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp> * test/mini/test_mini_test.rb: recovered. diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index db243c4e7e..c9d1f009b1 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1217,6 +1217,34 @@ strio_truncate(VALUE self, VALUE len) } /* + * call-seq: + * strio.external_encoding => encoding + * + * Returns the Encoding object that represents the encoding of the file. + * If strio is write mode and no encoding is specified, returns <code>nil</code>. + */ + +static VALUE +strio_external_encoding(VALUE self) +{ + return rb_enc_from_encoding(rb_enc_get(StringIO(self)->string)); +} + +/* + * call-seq: + * strio.internal_encoding => encoding + * + * Returns the Encoding of the internal string if conversion is + * specified. Otherwise returns nil. + */ + +static VALUE +strio_internal_encoding(VALUE self) +{ + return Qnil; +} + +/* * Pseudo I/O on String object. */ void @@ -1291,4 +1319,7 @@ Init_stringio() rb_define_method(StringIO, "size", strio_size, 0); rb_define_method(StringIO, "length", strio_size, 0); rb_define_method(StringIO, "truncate", strio_truncate, 1); + + rb_define_method(StringIO, "external_encoding", strio_external_encoding, 0); + rb_define_method(StringIO, "internal_encoding", strio_internal_encoding, 0); } |