Class: CharDet::CodingStateMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/rchardet/codingstatemachine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sm) ⇒ CodingStateMachine

Returns a new instance of CodingStateMachine.



33
34
35
36
37
38
# File 'lib/rchardet/codingstatemachine.rb', line 33

def initialize(sm)
  @_mModel = sm
  @_mCurrentBytePos = 0
  @_mCurrentCharLen = 0
  reset()
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



31
32
33
# File 'lib/rchardet/codingstatemachine.rb', line 31

def active
  @active
end

Instance Method Details

#coding_state_machineObject



62
63
64
# File 'lib/rchardet/codingstatemachine.rb', line 62

def coding_state_machine
  return @_mModel['name']
end

#current_charlenObject



58
59
60
# File 'lib/rchardet/codingstatemachine.rb', line 58

def current_charlen
  return @_mCurrentCharLen
end

#next_state(c) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# 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
  byteCls = @_mModel['classTable'][c[0].ord]
  if @_mCurrentState == EStart
    @_mCurrentBytePos = 0
    @_mCurrentCharLen = @_mModel['charLenTable'][byteCls]
  end
  # from byte's class and stateTable, we get its next state
  @_mCurrentState = @_mModel['stateTable'][@_mCurrentState * @_mModel['classFactor'] + byteCls]
  @_mCurrentBytePos += 1
  return @_mCurrentState
end

#resetObject



40
41
42
# File 'lib/rchardet/codingstatemachine.rb', line 40

def reset
  @_mCurrentState = EStart
end