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

ruby-changes:22490

From: naruse <ko1@a...>
Date: Sat, 11 Feb 2012 03:14:25 +0900 (JST)
Subject: [ruby-changes:22490] naruse:r34539 (ruby_1_9_3): merge revision(s) 33200: [Backport #5794]

naruse	2012-02-11 03:13:56 +0900 (Sat, 11 Feb 2012)

  New Revision: 34539

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

  Log:
    merge revision(s) 33200: [Backport #5794]
    
    * transcode.c: enabled econv newline option.

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/test/ruby/test_econv.rb
    branches/ruby_1_9_3/transcode.c
    branches/ruby_1_9_3/version.h

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 34538)
+++ ruby_1_9_3/ChangeLog	(revision 34539)
@@ -1,3 +1,7 @@
+Sat Feb 11 03:13:27 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* transcode.c: enabled econv newline option.
+
 Sat Feb 11 02:39:09 2012  CHIKANAGA Tomoyuki  <nagachika00@g...>
 
 	* variable.c (set_const_visibility): clear inine-cache when constant's
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 34538)
+++ ruby_1_9_3/version.h	(revision 34539)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 84
+#define RUBY_PATCHLEVEL 85
 
 #define RUBY_RELEASE_DATE "2012-02-11"
 #define RUBY_RELEASE_YEAR 2012
Index: ruby_1_9_3/test/ruby/test_econv.rb
===================================================================
--- ruby_1_9_3/test/ruby/test_econv.rb	(revision 34538)
+++ ruby_1_9_3/test/ruby/test_econv.rb	(revision 34539)
@@ -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: ruby_1_9_3/transcode.c
===================================================================
--- ruby_1_9_3/transcode.c	(revision 34538)
+++ ruby_1_9_3/transcode.c	(revision 34539)
@@ -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;
@@ -1889,6 +1891,7 @@
         return -1;
 
     tr = load_transcoder_entry(entry);
+    if (!tr) return -1;
 
     return rb_econv_add_transcoder_at(ec, tr, n);
 }
@@ -3112,11 +3115,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>]]
@@ -3261,6 +3268,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
@@ -3509,7 +3519,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) {
@@ -4388,6 +4437,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/

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