class CharDet::CodingStateMachine

Attributes

active[RW]

Public Class Methods

new(sm) click to toggle source
# File lib/rchardet/codingstatemachine.rb, line 33
def initialize(sm)
  @model = sm
  @currentBytePos = 0
  @currentCharLen = 0
  reset()
end

Public Instance Methods

get_coding_state_machine() click to toggle source
# File lib/rchardet/codingstatemachine.rb, line 63
def get_coding_state_machine
  return @model['name']
end
get_current_charlen() click to toggle source
# File lib/rchardet/codingstatemachine.rb, line 59
def get_current_charlen
  return @currentCharLen
end
next_state(c) click to toggle source
# File lib/rchardet/codingstatemachine.rb, line 44
def next_state(c)
  # for each byte we get its class
  # if it is first byte, we also get byte length
  b = c.bytes.first
  byteCls = @model['classTable'][b]
  if @currentState == EStart
    @currentBytePos = 0
    @currentCharLen = @model['charLenTable'][byteCls]
  end
  # from byte's class and stateTable, we get its next state
  @currentState = @model['stateTable'][@currentState * @model['classFactor'] + byteCls]
  @currentBytePos += 1
  return @currentState
end
reset() click to toggle source
# File lib/rchardet/codingstatemachine.rb, line 40
def reset
  @currentState = EStart
end