Class: Iconv

Inherits:
Object
  • Object
show all
Defined in:
lib/whisper/rfc2047.rb

Overview

stolen from sup

Class Method Summary collapse

Class Method Details

.easy_decode(target, charset, text) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/whisper/rfc2047.rb', line 23

def self.easy_decode target, charset, text
  return text if charset =~ /^(x-unknown|unknown[-_ ]?8bit|ascii[-_ ]?7[-_ ]?bit)$/i
  charset = case charset
              when /UTF[-_ ]?8/i; "utf-8"
              when /(iso[-_ ])?latin[-_ ]?1$/i; "ISO-8859-1"
              when /iso[-_ ]?8859[-_ ]?15/i; 'ISO-8859-15'
              when /unicode[-_ ]1[-_ ]1[-_ ]utf[-_]7/i; "utf-7"
              else charset
            end

  # Convert:
  #
  # Remember - Iconv.open(to, from)!
  Iconv.iconv(target + "//IGNORE", charset, text + " ").join[0 .. -2]
end