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)
  @model = sm
  @currentBytePos = 0
  @currentCharLen = 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

#get_coding_state_machineObject



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

def get_coding_state_machine
  return @model['name']
end

#get_current_charlenObject



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

def get_current_charlen
  return @currentCharLen
end

#next_state(c) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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

#resetObject



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

def reset
  @currentState = EStart
end