Class: AudioTag::ID3::V2::TextDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/audio_tag/id3/v2/text_decoder.rb

Constant Summary collapse

ENCODINGS =
{
  ascii:    /^\x00(.*?)(\x00)?$/,
  utf_16:   /^\x01(.*?)(\x00\x00)?$/,
  utf_16be: /^\x02(.*?)(\x00\x00)?$/,
  utf_8:    /^\x03(.*?)(\x00)?$/
}.freeze

Class Method Summary collapse

Class Method Details

.decode(string) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/audio_tag/id3/v2/text_decoder.rb', line 21

def self.decode(string)
  case encoding(string)
  when :ascii    then string.gsub(ENCODINGS[:ascii],    "\\1")
  when :utf_16   then string.gsub(ENCODINGS[:utf_16],   "\\1")
  when :utf_16be then string.gsub(ENCODINGS[:utf_16be], "\\1")
  when :utf_8    then string.gsub(ENCODINGS[:utf_8],    "\\1")
  else string
  end
end

.encoding(string) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/audio_tag/id3/v2/text_decoder.rb', line 12

def self.encoding(string)
  case string
  when ENCODINGS[:ascii]    then :ascii
  when ENCODINGS[:utf_16]   then :utf_16
  when ENCODINGS[:utf_16be] then :utf_16be
  when ENCODINGS[:utf_8]    then :utf_8
  end
end