summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-27 02:16:12 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-27 02:16:12 +0000
commit6a1c295da6347c5574b9a825567d20459dffe512 (patch)
treeccdd447a64f515d8ccfc36673c1abf7946e77eb5 /lib
parent2b29e9f40edd3955f133fb1fa23a3b8be4384a08 (diff)
merges r21074 from trunk into ruby_1_9_1.
* lib/csv.rb: Using a more robust transcoding scheme to produce ASCII compatible inspect() messages. [ruby-dev:37591] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/csv.rb24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/csv.rb b/lib/csv.rb
index 6fb5da4d79..fd83fdc354 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -199,7 +199,7 @@ require "stringio"
#
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 @@ class CSV
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 @@ class CSV
":" << 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 @@ class CSV
#
# 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 @@ class CSV
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