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

ruby-changes:21151

From: nobu <ko1@a...>
Date: Tue, 6 Sep 2011 12:07:27 +0900 (JST)
Subject: [ruby-changes:21151] nobu:r33200 (trunk): * transcode.c: enabled econv newline option.

nobu	2011-09-06 12:07:16 +0900 (Tue, 06 Sep 2011)

  New Revision: 33200

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

  Log:
    * transcode.c: enabled econv newline option.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_econv.rb
    trunk/transcode.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33199)
+++ ChangeLog	(revision 33200)
@@ -1,3 +1,7 @@
+Tue Sep  6 12:07:10 2011  Nobuyoshi Nakada  <nobu@r...>
+
+	* transcode.c: enabled econv newline option.
+
 Tue Sep  6 06:44:57 2011  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* numeric.c (dbl2ival): Fix Float#divmod and #round for 32 bit
Index: test/ruby/test_econv.rb
===================================================================
--- test/ruby/test_econv.rb	(revision 33199)
+++ test/ruby/test_econv.rb	(revision 33200)
@@ -902,4 +902,10 @@
       "".encode("euc-jp", :undef => :replace, :replace => broken)
     }
   end
+
+  def test_newline_option
+    ec1 = Encoding::Converter.new("", "", universal_newline: true)
+    ec2 = Encoding::Converter.new("", "", newline: :universal)
+    assert_equal(ec1, ec2)
+  end
 end
Index: transcode.c
===================================================================
--- transcode.c	(revision 33199)
+++ transcode.c	(revision 33200)
@@ -15,6 +15,8 @@
 #include "transcode_data.h"
 #include <ctype.h>
 
+#define ENABLE_ECONV_NEWLINE_OPTION 1
+
 /* VALUE rb_cEncoding = rb_define_class("Encoding", rb_cObject); */
 VALUE rb_eUndefinedConversionError;
 VALUE rb_eInvalidByteSequenceError;
@@ -1884,6 +1886,7 @@
         return -1;
 
     tr = load_transcoder_entry(entry);
+    if (!tr) return -1;
 
     return rb_econv_add_transcoder_at(ec, tr, n);
 }
@@ -3107,11 +3110,15 @@
  *   #    [#<Encoding:UTF-8>, #<Encoding:EUC-JP>]]
  *
  *   p Encoding::Converter.search_convpath("ISO-8859-1", "EUC-JP", universal_newline: true)
+ *   or
+ *   p Encoding::Converter.search_convpath("ISO-8859-1", "EUC-JP", newline: :universal)
  *   #=> [[#<Encoding:ISO-8859-1>, #<Encoding:UTF-8>],
  *   #    [#<Encoding:UTF-8>, #<Encoding:EUC-JP>],
  *   #    "universal_newline"]
  *
  *   p Encoding::Converter.search_convpath("ISO-8859-1", "UTF-32BE", universal_newline: true)
+ *   or
+ *   p Encoding::Converter.search_convpath("ISO-8859-1", "UTF-32BE", newline: :universal)
  *   #=> [[#<Encoding:ISO-8859-1>, #<Encoding:UTF-8>],
  *   #    "universal_newline",
  *   #    [#<Encoding:UTF-8>, #<Encoding:UTF-32BE>]]
@@ -3256,6 +3263,9 @@
  *     :undef => nil              # raise error on undefined conversion (default)
  *     :undef => :replace         # replace undefined conversion
  *     :replace => string         # replacement string ("?" or "\uFFFD" if not specified)
+ *     :newline => :universal     # decorator for converting CRLF and CR to LF
+ *     :newline => :crlf          # decorator for converting LF to CRLF
+ *     :newline => :cr            # decorator for converting LF to CR
  *     :universal_newline => true # decorator for converting CRLF and CR to LF
  *     :crlf_newline => true      # decorator for converting LF to CRLF
  *     :cr_newline => true        # decorator for converting LF to CR
@@ -3504,7 +3514,46 @@
     return result;
 }
 
+/*
+ * call-seq:
+ *   ec == other        -> true or false
+ */
 static VALUE
+econv_equal(VALUE self, VALUE other)
+{
+    rb_econv_t *ec1 = check_econv(self);
+    rb_econv_t *ec2;
+    int i;
+
+    if (!rb_typeddata_is_kind_of(other, &econv_data_type)) {
+	return Qnil;
+    }
+    ec2 = DATA_PTR(other);
+    if (!ec2) return Qfalse;
+    if (ec1->source_encoding_name != ec2->source_encoding_name &&
+	strcmp(ec1->source_encoding_name, ec2->source_encoding_name))
+	return Qfalse;
+    if (ec1->destination_encoding_name != ec2->destination_encoding_name &&
+	strcmp(ec1->destination_encoding_name, ec2->destination_encoding_name))
+	return Qfalse;
+    if (ec1->flags != ec2->flags) return Qfalse;
+    if (ec1->replacement_enc != ec2->replacement_enc &&
+	strcmp(ec1->replacement_enc, ec2->replacement_enc))
+	return Qfalse;
+    if (ec1->replacement_len != ec2->replacement_len) return Qfalse;
+    if (ec1->replacement_str != ec2->replacement_str &&
+	memcmp(ec1->replacement_str, ec2->replacement_str, ec2->replacement_len))
+	return Qfalse;
+
+    if (ec1->num_trans != ec2->num_trans) return Qfalse;
+    for (i = 0; i < ec1->num_trans; i++) {
+        if (ec1->elems[i].tc->transcoder != ec2->elems[i].tc->transcoder)
+	    return Qfalse;
+    }
+    return Qtrue;
+}
+
+static VALUE
 econv_result_to_symbol(rb_econv_result_t res)
 {
     switch (res) {
@@ -4383,6 +4432,7 @@
     rb_define_method(rb_cEncodingConverter, "last_error", econv_last_error, 0);
     rb_define_method(rb_cEncodingConverter, "replacement", econv_get_replacement, 0);
     rb_define_method(rb_cEncodingConverter, "replacement=", econv_set_replacement, 1);
+    rb_define_method(rb_cEncodingConverter, "==", econv_equal, 1);
 
     rb_define_const(rb_cEncodingConverter, "INVALID_MASK", INT2FIX(ECONV_INVALID_MASK));
     rb_define_const(rb_cEncodingConverter, "INVALID_REPLACE", INT2FIX(ECONV_INVALID_REPLACE));

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

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