mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (rb_io_external_encoding): new method.
* encoding.c (rb_enc_from_encoding): returns Qnil for NULL encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
65a953c7c9
commit
1b27cfcd6c
3 changed files with 28 additions and 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>
|
Fri Dec 21 13:09:11 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* encoding.c (rb_locale_charmap): return nil if no locale information.
|
* encoding.c (rb_locale_charmap): return nil if no locale information.
|
||||||
|
|
|
@ -51,7 +51,7 @@ enc_new(rb_encoding *encoding)
|
||||||
VALUE
|
VALUE
|
||||||
rb_enc_from_encoding(rb_encoding *encoding)
|
rb_enc_from_encoding(rb_encoding *encoding)
|
||||||
{
|
{
|
||||||
if (!encoding) return 0;
|
if (!encoding) return Qnil;
|
||||||
if (enc_initialized_p(encoding))
|
if (enc_initialized_p(encoding))
|
||||||
return ENC_FROM_ENCODING(encoding);
|
return ENC_FROM_ENCODING(encoding);
|
||||||
return enc_new(encoding);
|
return enc_new(encoding);
|
||||||
|
|
20
io.c
20
io.c
|
@ -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);
|
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
|
static VALUE
|
||||||
argf_tell(void)
|
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, "pid", rb_io_pid, 0);
|
||||||
rb_define_method(rb_cIO, "inspect", rb_io_inspect, 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_define_variable("$stdin", &rb_stdin);
|
||||||
rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO, "<STDIN>");
|
rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO, "<STDIN>");
|
||||||
rb_define_hooked_variable("$stdout", &rb_stdout, 0, stdout_setter);
|
rb_define_hooked_variable("$stdout", &rb_stdout, 0, stdout_setter);
|
||||||
|
|
Loading…
Add table
Reference in a new issue