diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-21 04:26:38 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-21 04:26:38 +0000 |
| commit | d8e8231c22e0c31e76a30ab86faf2723f9c6dd53 (patch) | |
| tree | b921c8618fbacd59c47fba4d80935edc41659c12 | |
| parent | 43bc9c1ef979719fe47462e2ae9e370f65df602a (diff) | |
| download | ruby-d8e8231c22e0c31e76a30ab86faf2723f9c6dd53.tar.gz ruby-d8e8231c22e0c31e76a30ab86faf2723f9c6dd53.tar.xz ruby-d8e8231c22e0c31e76a30ab86faf2723f9c6dd53.zip | |
* io.c (rb_io_external_encoding): new method.
* encoding.c (rb_enc_from_encoding): returns Qnil for NULL
encoding.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 7 | ||||
| -rw-r--r-- | encoding.c | 2 | ||||
| -rw-r--r-- | io.c | 20 |
3 files changed, 28 insertions, 1 deletions
@@ -1,3 +1,10 @@ +Fri Dec 21 13:10:57 2007 Yukihiro Matsumoto <matz@ruby-lang.org> + + * io.c (rb_io_external_encoding): new method. + + * encoding.c (rb_enc_from_encoding): returns Qnil for NULL + encoding. + Fri Dec 21 13:09:11 2007 Tanaka Akira <akr@fsij.org> * encoding.c (rb_locale_charmap): return nil if no locale information. diff --git a/encoding.c b/encoding.c index 1af3c4422..6ff8fb6aa 100644 --- a/encoding.c +++ b/encoding.c @@ -51,7 +51,7 @@ enc_new(rb_encoding *encoding) VALUE rb_enc_from_encoding(rb_encoding *encoding) { - if (!encoding) return 0; + if (!encoding) return Qnil; if (enc_initialized_p(encoding)) return ENC_FROM_ENCODING(encoding); return enc_new(encoding); @@ -5657,6 +5657,24 @@ rb_io_s_read(int argc, VALUE *argv, VALUE io) return rb_ensure(io_s_read, (VALUE)&arg, rb_io_close, arg.io); } + +/* + * call-seq: + * io.externalencoding => encoding + * + * Returns the Encoding object that represents the encoding of the file. + */ + +static VALUE +rb_io_external_encoding(VALUE io) +{ + rb_io_t *fptr; + + GetOpenFile(io, fptr); + return rb_enc_from_encoding(fptr->enc); +} + + static VALUE argf_tell(void) { @@ -6232,6 +6250,8 @@ Init_IO(void) rb_define_method(rb_cIO, "pid", rb_io_pid, 0); rb_define_method(rb_cIO, "inspect", rb_io_inspect, 0); + rb_define_method(rb_cIO, "external_encoding", rb_io_external_encoding, 0); + rb_define_variable("$stdin", &rb_stdin); rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO, "<STDIN>"); rb_define_hooked_variable("$stdout", &rb_stdout, 0, stdout_setter); |
