[前][次][番号順一覧][スレッド一覧]

ruby-changes:2906

From: ko1@a...
Date: 21 Dec 2007 13:27:04 +0900
Subject: [ruby-changes:2906] matz - Ruby:r14397 (trunk): * io.c (rb_io_external_encoding): new method.

matz	2007-12-21 13:26:38 +0900 (Fri, 21 Dec 2007)

  New Revision: 14397

  Modified files:
    trunk/ChangeLog
    trunk/encoding.c
    trunk/io.c

  Log:
    * io.c (rb_io_external_encoding): new method.
    
    * encoding.c (rb_enc_from_encoding): returns Qnil for NULL
      encoding.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14397&r2=14396
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/io.c?r1=14397&r2=14396
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/encoding.c?r1=14397&r2=14396

Index: encoding.c
===================================================================
--- encoding.c	(revision 14396)
+++ encoding.c	(revision 14397)
@@ -51,7 +51,7 @@
 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);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14396)
+++ ChangeLog	(revision 14397)
@@ -1,3 +1,10 @@
+Fri Dec 21 13:10:57 2007  Yukihiro Matsumoto  <matz@r...>
+
+	* 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@f...>
 
 	* encoding.c (rb_locale_charmap): return nil if no locale information.
Index: io.c
===================================================================
--- io.c	(revision 14396)
+++ io.c	(revision 14397)
@@ -5657,7 +5657,25 @@
     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)
 {
     if (!next_argv()) {
@@ -6232,6 +6250,8 @@
     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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]