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 | 536e1170332525134e6597764b75e6b46f475516 (patch) | |
tree | fcb7bd6d9dd4bcd2e4f03bf559e9f62573cb3caa /ext | |
parent | 16a89660f3609acb317f1d131a1a20f19efde23f (diff) | |
download | ruby-536e1170332525134e6597764b75e6b46f475516.tar.gz ruby-536e1170332525134e6597764b75e6b46f475516.tar.xz ruby-536e1170332525134e6597764b75e6b46f475516.zip |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@19674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-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 db243c4e7..c9d1f009b 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); } |