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

ruby-changes:2122

From: ko1@a...
Date: 4 Oct 2007 15:57:31 +0900
Subject: [ruby-changes:2122] nobu - Ruby:r13613 (trunk): * encoding.c (rb_obj_encoding): returns encoding of the given object.

nobu	2007-10-04 15:57:19 +0900 (Thu, 04 Oct 2007)

  New Revision: 13613

  Modified files:
    trunk/ChangeLog
    trunk/encoding.c
    trunk/include/ruby/encoding.h
    trunk/re.c
    trunk/string.c

  Log:
    * encoding.c (rb_obj_encoding): returns encoding of the given object.
    
    * re.c (Init_Regexp): new method Regexp#encoding.
    
    * string.c (str_encoding): moved to encoding.c


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=13613&r2=13612
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13613&r2=13612
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/encoding.h?r1=13613&r2=13612
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/re.c?r1=13613&r2=13612
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/encoding.c?r1=13613&r2=13612

Index: encoding.c
===================================================================
--- encoding.c	(revision 13612)
+++ encoding.c	(revision 13613)
@@ -259,6 +259,20 @@
 }
 
 
+/*
+ *  call-seq:
+ *     obj.encoding   => str
+ *
+ *  Retruns the encoding name.
+ */
+
+VALUE
+rb_obj_encoding(VALUE obj)
+{
+    return rb_str_new2(rb_enc_name(rb_enc_get(obj)));
+}
+
+
 char*
 rb_enc_nth(const char *p, const char *e, int nth, rb_encoding *enc)
 {
Index: include/ruby/encoding.h
===================================================================
--- include/ruby/encoding.h	(revision 13612)
+++ include/ruby/encoding.h	(revision 13613)
@@ -50,6 +50,7 @@
 VALUE rb_enc_str_new(const char*, long len, rb_encoding*);
 long rb_enc_strlen(const char*, const char*, rb_encoding*);
 char* rb_enc_nth(const char*, const char*, int, rb_encoding*);
+VALUE rb_obj_encoding(VALUE);
 
 /* index -> rb_encoding */
 rb_encoding* rb_enc_from_index(int idx);
Index: re.c
===================================================================
--- re.c	(revision 13612)
+++ re.c	(revision 13613)
@@ -2476,6 +2476,7 @@
     rb_define_method(rb_cRegexp, "casefold?", rb_reg_casefold_p, 0);
     rb_define_method(rb_cRegexp, "options", rb_reg_options_m, 0);
     rb_define_method(rb_cRegexp, "kcode", rb_reg_kcode_m, 0);
+    rb_define_method(rb_cRegexp, "encoding", rb_obj_encoding, 0); /* in encoding.c */
 
     rb_define_const(rb_cRegexp, "IGNORECASE", INT2FIX(ONIG_OPTION_IGNORECASE));
     rb_define_const(rb_cRegexp, "EXTENDED", INT2FIX(ONIG_OPTION_EXTEND));
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13612)
+++ ChangeLog	(revision 13613)
@@ -1,3 +1,11 @@
+Thu Oct  4 15:57:16 2007  Nobuyoshi Nakada  <nobu@r...>
+
+	* encoding.c (rb_obj_encoding): returns encoding of the given object.
+
+	* re.c (Init_Regexp): new method Regexp#encoding.
+
+	* string.c (str_encoding): moved to encoding.c
+
 Thu Oct  4 15:49:33 2007  Yukihiro Matsumoto  <matz@r...>
 
 	* array.c (rb_ary_permutation): remove C99 dependency.
Index: string.c
===================================================================
--- string.c	(revision 13612)
+++ string.c	(revision 13613)
@@ -5108,20 +5108,6 @@
 
 /*
  *  call-seq:
- *     str.encoding   => str
- *
- *  Retruns the encoding name.
- */
-
-static VALUE
-str_encoding(VALUE str)
-{
-    return rb_str_new2(rb_enc_name(rb_enc_get(str)));
-}
-
-
-/*
- *  call-seq:
  *     str.force_encoding(encoding)   => str
  *
  *  Changes the encoding to +encoding+ and returns self.
@@ -5388,7 +5374,7 @@
 static VALUE
 sym_encoding(VALUE sym)
 {
-    return str_encoding(rb_id2str(SYM2ID(sym)));
+    return rb_obj_encoding(rb_id2str(SYM2ID(sym)));
 }
 
 ID
@@ -5545,7 +5531,7 @@
     rb_define_method(rb_cString, "partition", rb_str_partition, 1);
     rb_define_method(rb_cString, "rpartition", rb_str_rpartition, 1);
 
-    rb_define_method(rb_cString, "encoding", str_encoding, 0);
+    rb_define_method(rb_cString, "encoding", rb_obj_encoding, 0); /* in encoding.c */
     rb_define_method(rb_cString, "force_encoding", rb_str_force_encoding, 1);
 
     id_to_s = rb_intern("to_s");

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

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