class TSparser::AribStringDecoder::Decoder::Decoded

Inner class to retain decoded string.

Constants

CODE_ZENKAKU

Public Class Methods

new() click to toggle source
# File lib/arib_string_decoder.rb, line 383
def initialize
  @decoded_utf_8 = "".encode(Encoding::UTF_8)
  @buffer        = Binary.new
end

Public Instance Methods

code_type_change(type) click to toggle source
# File lib/arib_string_decoder.rb, line 414
def code_type_change(type)
  return false if @buffer_current_code_type == type
  @buffer_current_code_type = type
  return true
end
convert_buffer() click to toggle source
# File lib/arib_string_decoder.rb, line 420
def convert_buffer
  unless @buffer.empty?
    @decoded_utf_8 << @buffer.encode(Encoding::UTF_8, Encoding::ISO_2022_JP)
    @buffer.clear
    @buffer_current_code_type = nil
  end
rescue => error
  STDERR.puts "Convert error."
  STDERR.puts "Now buffer(binary): #{@bugger.dump}"
  STDERR.puts "Now decoded(utf-8): #{decoded_utf_8}"
  raise error
end
push_jis_ascii(byte) click to toggle source
# File lib/arib_string_decoder.rb, line 393
def push_jis_ascii(byte)
  if code_type_change(CODE_ASCII)
    @buffer << Binary.from_int(ESC, 0x28, 0x42)
  end
  @buffer << byte
end
push_jis_hankaku(byte) click to toggle source
# File lib/arib_string_decoder.rb, line 400
def push_jis_hankaku(byte)
  if code_type_change(CODE_HANKAKU)
    @buffer << Binary.from_int(ESC, 0x28, 0x49)
  end
  @buffer << byte
end
push_jis_zenkaku(byte1, byte2) click to toggle source
# File lib/arib_string_decoder.rb, line 407
def push_jis_zenkaku(byte1, byte2)
  if code_type_change(CODE_ZENKAKU)
    @buffer << Binary.from_int(ESC, 0x24, 0x42)
  end
  @buffer << byte1 << byte2
end
push_str(string) click to toggle source
# File lib/arib_string_decoder.rb, line 388
def push_str(string)
  convert_buffer
  @decoded_utf_8 << string
end
to_s() click to toggle source
# File lib/arib_string_decoder.rb, line 433
def to_s
  convert_buffer
  return @decoded_utf_8
end