Class: Mp3Info::EncodingHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/mp3info/extension_modules.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.convert_from_iso_8859_1(value) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/mp3info/extension_modules.rb', line 58

def self.convert_from_iso_8859_1(value)
  if RUBY_1_8
    ruby_18_encode("utf-8", "iso-8859-1", value)
  else
    value.force_encoding("iso-8859-1").encode("utf-8")
  end
end

.convert_to(value, from, to) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mp3info/extension_modules.rb', line 43

def self.convert_to(value, from, to)
  if RUBY_1_8
    if to == "iso-8859-1"
      to = to + "//TRANSLIT"
    end
    ruby_18_encode(from, to, value)
  else
    if to == "utf-16"
      ("\uFEFF" +  value).encode("UTF-16LE") # Chab 01.apr.2012 : moved from big to little endian for more compatibility (Windows Media Player, older Quicktime..)
    else
      value.encode(to)
    end
  end
end

.decode_utf16(out) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/mp3info/extension_modules.rb', line 70

def self.decode_utf16(out)
  if RUBY_1_8
    convert_to(out, "UTF-8", "UTF-16")
  else
    if out.bytes.first == 0xff
      tag_encoding = "UTF-16LE"
    else
      tag_encoding = "UTF-16BE"
    end
    out = out.dup.force_encoding(tag_encoding)[1..-1]
  end
end

.ruby_18_encode(from, to, value) ⇒ Object



66
67
68
# File 'lib/mp3info/extension_modules.rb', line 66

def self.ruby_18_encode(from, to, value)
  Iconv.iconv(to, from, value).first
end