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

ruby-changes:8076

From: jeg2 <ko1@a...>
Date: Sun, 28 Sep 2008 09:09:34 +0900 (JST)
Subject: [ruby-changes:8076] Ruby:r19602 (trunk): * lib/csv/csv.rb: Worked around some minor encoding changes in Ruby

jeg2	2008-09-28 09:06:21 +0900 (Sun, 28 Sep 2008)

  New Revision: 19602

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

  Log:
    * lib/csv/csv.rb:  Worked around some minor encoding changes in Ruby
      pointed out by Nobu.

  Modified files:
    trunk/ChangeLog
    trunk/lib/csv.rb
    trunk/test/csv/tc_csv_parsing.rb
    trunk/test/csv/tc_encodings.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19601)
+++ ChangeLog	(revision 19602)
@@ -1,3 +1,8 @@
+Sun Sep 28 09:05:53 2008  James Edward Gray II  <jeg2@r...>
+
+	* lib/csv/csv.rb:  Worked around some minor encoding changes in Ruby
+	  pointed out by Nobu.
+
 Sun Sep 28 08:37:12 2008  Tadayoshi Funaba  <tadf@d...>
 
 	* lib/mathn.rb: a hack to provide canonicalization.  This must be
Index: lib/csv.rb
===================================================================
--- lib/csv.rb	(revision 19601)
+++ lib/csv.rb	(revision 19602)
@@ -199,7 +199,7 @@
 # 
 class CSV
   # The version of the installed library.
-  VERSION = "2.4.1".freeze
+  VERSION = "2.4.2".freeze
   
   # 
   # A CSV::Row is part Array and part Hash.  It retains an order for the fields
@@ -831,7 +831,7 @@
     
     # Shows the mode and size of this table in a US-ASCII String.
     def inspect
-      "#<#{self.class} mode:#{@mode} row_count:#{to_a.size}>"
+      "#<#{self.class} mode:#{@mode} row_count:#{to_a.size}>".encode("US-ASCII")
     end
   end
 
@@ -1244,9 +1244,9 @@
     encoding = options.delete(:encoding)
     str      = ""
     if encoding
-      str.encode!(encoding)
+      str.force_encoding(encoding)
     elsif field = row.find { |f| not f.nil? }
-      str.encode!(String(field).encoding)
+      str.force_encoding(String(field).encoding)
     end
     (new(str, options) << row).string
   end
Index: test/csv/tc_encodings.rb
===================================================================
--- test/csv/tc_encodings.rb	(revision 19601)
+++ test/csv/tc_encodings.rb	(revision 19602)
@@ -207,8 +207,8 @@
       
       # writing to files
       data = encode_ary([%w[abc d,ef], %w[123 456 ]], encoding)
-      CSV.open(@temp_csv_path, "wb:#{encoding.name}") do |csv|
-        data.each { |row| csv << row }
+      CSV.open(@temp_csv_path, "wb:#{encoding.name}") do |f|
+        data.each { |row| f << row }
       end
       assert_equal(data, CSV.read(@temp_csv_path, :encoding => encoding.name))
     end
@@ -221,8 +221,9 @@
     fields   = encode_ary(fields, encoding)
     parsed   = CSV.parse(ary_to_data(fields, options), options)
     assert_equal(fields, parsed)
-    assert( parsed.flatten.all? { |field| field.encoding == encoding },
-            "Fields were transcoded." )
+    parsed.flatten.each_with_index do |field, i|
+      assert_equal(encoding, field.encoding, "Field[#{i + 1}] was transcoded.")
+    end
   end
   
   def encode_ary(ary, encoding)
Index: test/csv/tc_csv_parsing.rb
===================================================================
--- test/csv/tc_csv_parsing.rb	(revision 19601)
+++ test/csv/tc_csv_parsing.rb	(revision 19602)
@@ -141,7 +141,7 @@
       assert_equal( "Unquoted fields do not allow \\r or \\n (line 4).",
                     $!.message )
     end
-
+  
     assert_raise(CSV::MalformedCSVError) { CSV.parse_line('1,2,"3...') }
     
     bad_data = <<-END_DATA.gsub(/^ +/, "")

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

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