From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.90.87.14 with SMTP id k14cs1331989agb; Thu, 31 Dec 2009 15:44:06 -0800 (PST) Received: by 10.224.95.170 with SMTP id d42mr9565792qan.261.1262303046402; Thu, 31 Dec 2009 15:44:06 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id 38si22753714qyk.85.2009.12.31.15.44.06; Thu, 31 Dec 2009 15:44:06 -0800 (PST) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id DA1B8167830D; Thu, 31 Dec 2009 18:44:05 -0500 (EST) Received: from magnesium.club.cc.cmu.edu (MAGNESIUM.CLUB.CC.cmu.edu [128.237.157.15]) by rubyforge.org (Postfix) with ESMTP id 138E21858249 for ; Thu, 31 Dec 2009 18:44:03 -0500 (EST) Received: (qmail 32738 invoked from network); 31 Dec 2009 23:37:23 -0000 Received: from pion.club.cc.cmu.edu (HELO localhost.localdomain) (128.237.157.88) by magnesium.club.cc.cmu.edu with SMTP; 31 Dec 2009 23:37:23 -0000 From: Rich Lane To: sup-devel@rubyforge.org Date: Thu, 31 Dec 2009 15:36:53 -0800 Message-Id: <1262302618-20503-6-git-send-email-rlane@club.cc.cmu.edu> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1262302618-20503-5-git-send-email-rlane@club.cc.cmu.edu> References: <1262302618-20503-1-git-send-email-rlane@club.cc.cmu.edu> <1262302618-20503-2-git-send-email-rlane@club.cc.cmu.edu> <1262302618-20503-3-git-send-email-rlane@club.cc.cmu.edu> <1262302618-20503-4-git-send-email-rlane@club.cc.cmu.edu> <1262302618-20503-5-git-send-email-rlane@club.cc.cmu.edu> Subject: [sup-devel] [PATCH 05/10] fixup Iconv#easy_decode for Ruby 1.9 X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org --- lib/sup/util.rb | 21 +++++++++++++-------- 1 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/sup/util.rb b/lib/sup/util.rb index 508bcee..560ac73 100644 --- a/lib/sup/util.rb +++ b/lib/sup/util.rb @@ -664,21 +664,26 @@ class FinishLine end class Iconv - def self.easy_decode target, charset, text - return text if charset =~ /^(x-unknown|unknown[-_ ]?8bit|ascii[-_ ]?7[-_ ]?bit)$/i - charset = case charset + def self.easy_decode target, orig_charset, text + if text.respond_to? :force_encoding + text = text.dup + text.force_encoding Encoding::BINARY + end + charset = case orig_charset when /UTF[-_ ]?8/i then "utf-8" when /(iso[-_ ])?latin[-_ ]?1$/i then "ISO-8859-1" when /iso[-_ ]?8859[-_ ]?15/i then 'ISO-8859-15' when /unicode[-_ ]1[-_ ]1[-_ ]utf[-_]7/i then "utf-7" - else charset + when /^euc$/i then 'EUC-JP' # XXX try them all? + when /^(x-unknown|unknown[-_ ]?8bit|ascii[-_ ]?7[-_ ]?bit)$/i then 'ASCII' + else orig_charset end begin - Iconv.iconv(target + "//IGNORE", charset, text + " ").join[0 .. -2] - rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::InvalidCharacter, Iconv::IllegalSequence => e - warn "couldn't transcode text from #{charset} to #{target} (\"#{text[0 ... 20]}\"...) (got #{e.message}); using original as is" - text + returning(Iconv.iconv(target, charset, text + " ").join[0 .. -2]) { |str| str.check } + rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::InvalidCharacter, Iconv::IllegalSequence, String::CheckError + warn "couldn't transcode text from #{orig_charset} (#{charset}) to #{target}) (#{text[0 ... 20].inspect}...) (got #{$!.message} (#{$!.class}))" + text.ascii end end end -- 1.6.3.3 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel