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



39
40
41
# File 'lib/mp3info/extension_modules.rb', line 39

def self.convert_from_iso_8859_1(value)
  value.force_encoding("iso-8859-1").encode("utf-8")
end

.convert_to(value, from, to) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/mp3info/extension_modules.rb', line 31

def self.convert_to(value, from, to)
  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

.decode_utf16(out) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/mp3info/extension_modules.rb', line 47

def self.decode_utf16(out)
  # String#bytes is not an array in Ruby 1.9
  bytes = out.bytes.to_a
  if out.length >= 2 and bytes[0] == 0xff and bytes[1] == 0xfe
    tag_encoding = "UTF-16LE"
    first_valid = 1
  elsif out.length >= 2 and bytes[0] == 0xfe and bytes[1] == 0xff
    tag_encoding = "UTF-16BE"
    first_valid = 1
  else
    # ID3v2.3.0 section 3.3 mandates a BOM but some software
    # erroneously omits it so we have to guess. Since most of
    # the world is little endian we might as well go with that.
    tag_encoding = "UTF-16LE"
    first_valid = 0
  end
  out = out.dup.force_encoding(tag_encoding)[first_valid..-1]
end

.ruby_18_encode(from, to, value) ⇒ Object



43
44
45
# File 'lib/mp3info/extension_modules.rb', line 43

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