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

ruby-changes:9535

From: jeg2 <ko1@a...>
Date: Sat, 27 Dec 2008 01:53:31 +0900 (JST)
Subject: [ruby-changes:9535] Ruby:r21074 (trunk): * lib/csv.rb: Using a more robust transcoding scheme to produce

jeg2	2008-12-27 01:53:13 +0900 (Sat, 27 Dec 2008)

  New Revision: 21074

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

  Log:
    * lib/csv.rb:  Using a more robust transcoding scheme to produce
      ASCII compatible inspect() messages.  [ruby-dev:37591]

  Modified files:
    trunk/ChangeLog
    trunk/lib/csv.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 21073)
+++ ChangeLog	(revision 21074)
@@ -1,3 +1,8 @@
+Sat Dec 27 01:52:39 2008  James Edward Gray II  <jeg2@r...>
+
+	* lib/csv.rb:  Using a more robust transcoding scheme to produce
+	  ASCII compatible inspect() messages.  [ruby-dev:37591]
+
 Fri Dec 26 18:04:10 2008  Tanaka Akira  <akr@f...>
 
 	* io.c (fptr_finalize): don't allocate objects if noraise.
Index: lib/csv.rb
===================================================================
--- lib/csv.rb	(revision 21073)
+++ lib/csv.rb	(revision 21074)
@@ -199,7 +199,7 @@
 # 
 class CSV
   # The version of the installed library.
-  VERSION = "2.4.4".freeze
+  VERSION = "2.4.5".freeze
   
   # 
   # A CSV::Row is part Array and part Hash.  It retains an order for the fields
@@ -487,7 +487,7 @@
     end
     alias_method :to_s, :to_csv
     
-    # A summary of fields, by header, in an ASCII-8BIT String.
+    # A summary of fields, by header, in an ASCII compatible String.
     def inspect
       str = ["#<", self.class.to_s]
       each do |header, field|
@@ -495,7 +495,14 @@
                ":" << field.inspect
       end
       str << ">"
-      str.map { |s| s.encode("ASCII-8BIT") }.join
+      begin
+        str.join
+      rescue  # any encoding error
+        str.map do |s|
+          e = Encoding::Converter.asciicompat_encoding(s.encoding)
+          e ? s.encode(e) : s.force_encoding("ASCII-8BIT")
+        end.join
+      end
     end
   end
   
@@ -1899,7 +1906,7 @@
   
   # 
   # Returns a simplified description of the key FasterCSV attributes in an
-  # ASCII-8BIT String.
+  # ASCII compatible String.
   # 
   def inspect
     str = ["<#", self.class.to_s, " io_type:"]
@@ -1926,7 +1933,14 @@
       str << " headers:" << headers.inspect
     end
     str << ">"
-    str.map { |s| s.encode("ASCII-8BIT") }.join
+    begin
+      str.join
+    rescue  # any encoding error
+      str.map do |s|
+        e = Encoding::Converter.asciicompat_encoding(s.encoding)
+        e ? s.encode(e) : s.force_encoding("ASCII-8BIT")
+      end.join
+    end
   end
   
   private

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

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