diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-04 09:56:20 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-04 09:56:20 +0000 |
commit | 0b18a77e7d03a0bbf06bed7b683bddbe1730d61b (patch) | |
tree | fcb7bd6d9dd4bcd2e4f03bf559e9f62573cb3caa /ext/stringio/stringio.c | |
parent | 5f898e44a788c1c174c7e8d92e35ea8700477bd4 (diff) | |
download | ruby-0b18a77e7d03a0bbf06bed7b683bddbe1730d61b.tar.gz |
* ext/stringio/stringio.c (strio_external_encoding): defined.
* ext/stringio/stringio.c (strio_internal_encoding): defined.
* ext/stringio/stringio.c (Init_stringio): define above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/stringio/stringio.c')
-rw-r--r-- | ext/stringio/stringio.c | 31 |
1 files changed, 31 insertions, 0 deletions
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); } |