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

ruby-changes:8194

From: naruse <ko1@a...>
Date: Thu, 9 Oct 2008 11:52:55 +0900 (JST)
Subject: [ruby-changes:8194] Ruby:r19722 (trunk): * encoding.c (Init_Encoding): new instance method Encoding#names,

naruse	2008-10-09 11:52:39 +0900 (Thu, 09 Oct 2008)

  New Revision: 19722

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19722

  Log:
    * encoding.c (Init_Encoding): new instance method Encoding#names,
      returns its name and alias names.
    
    * encoding.c (enc_names): defined for Encoding#names.
    
    * encoding.c (enc_names_i): defined for enc_names.

  Modified files:
    trunk/ChangeLog
    trunk/encoding.c

Index: encoding.c
===================================================================
--- encoding.c	(revision 19721)
+++ encoding.c	(revision 19722)
@@ -823,8 +823,37 @@
     return rb_usascii_str_new2(rb_enc_name((rb_encoding*)DATA_PTR(self)));
 }
 
+static int
+enc_names_i(st_data_t name, st_data_t idx, st_data_t ary)
+{
+    if ((int)idx == FIX2INT(rb_ary_entry(ary, 0))) {
+	VALUE str = rb_usascii_str_new2((char *)name);
+	OBJ_FREEZE(str);
+	rb_ary_push(ary, str);
+    }
+    return ST_CONTINUE;
+}
+
 /*
  * call-seq:
+ *   enc.names => array
+ *
+ * Returns the list of name and aliases of the encoding.
+ *
+ *   Encoding::WINDOWS_31J.names => ["Windows-31J", "CP932", "csWindows31J"]
+ */
+static VALUE
+enc_names(VALUE self)
+{
+    VALUE ary = rb_ary_new2(0);
+    rb_ary_push(ary, INT2FIX(rb_to_encoding_index(self)));
+    st_foreach(enc_table.names, enc_names_i, (st_data_t)ary);
+    rb_ary_shift(ary);
+    return ary;
+}
+
+/*
+ * call-seq:
  *   Encoding.list => [enc1, enc2, ...]
  *
  * Returns the list of loaded encodings.
@@ -1250,6 +1279,7 @@
     rb_define_method(rb_cEncoding, "to_s", enc_name, 0);
     rb_define_method(rb_cEncoding, "inspect", enc_inspect, 0);
     rb_define_method(rb_cEncoding, "name", enc_name, 0);
+    rb_define_method(rb_cEncoding, "names", enc_names, 0);
     rb_define_method(rb_cEncoding, "dummy?", enc_dummy_p, 0);
     rb_define_singleton_method(rb_cEncoding, "list", enc_list, 0);
     rb_define_singleton_method(rb_cEncoding, "name_list", rb_enc_name_list, 0);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19721)
+++ ChangeLog	(revision 19722)
@@ -1,3 +1,12 @@
+Thu Oct  9 11:29:33 2008  NARUSE, Yui  <naruse@r...>
+
+	* encoding.c (Init_Encoding): new instance method Encoding#names,
+	  returns its name and alias names.
+
+	* encoding.c (enc_names): defined for Encoding#names.
+
+	* encoding.c (enc_names_i): defined for enc_names.
+
 Thu Oct  9 08:47:38 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* thread.c (rb_thread_wait_fd_rw): should not block by select if

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

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