Class: GIGO::CharDet::CodingStateMachine
- Inherits:
-
Object
- Object
- GIGO::CharDet::CodingStateMachine
- Defined in:
- lib/gigo/rchardet/codingstatemachine.rb
Instance Method Summary collapse
- #get_coding_state_machine ⇒ Object
- #get_current_charlen ⇒ Object
-
#initialize(sm) ⇒ CodingStateMachine
constructor
A new instance of CodingStateMachine.
- #next_state(c) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(sm) ⇒ CodingStateMachine
Returns a new instance of CodingStateMachine.
31 32 33 34 35 36 |
# File 'lib/gigo/rchardet/codingstatemachine.rb', line 31 def initialize(sm) @_mModel = sm @_mCurrentBytePos = 0 @_mCurrentCharLen = 0 reset() end |
Instance Method Details
#get_coding_state_machine ⇒ Object
61 62 63 |
# File 'lib/gigo/rchardet/codingstatemachine.rb', line 61 def get_coding_state_machine return @_mModel['name'] end |
#get_current_charlen ⇒ Object
57 58 59 |
# File 'lib/gigo/rchardet/codingstatemachine.rb', line 57 def get_current_charlen return @_mCurrentCharLen end |
#next_state(c) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gigo/rchardet/codingstatemachine.rb', line 42 def next_state(c) # for each byte we get its class # if it is first byte, we also get byte length char = c.respond_to?(:bytes) ? c.bytes.first : c[0] byteCls = @_mModel['classTable'][char] 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 |
#reset ⇒ Object
38 39 40 |
# File 'lib/gigo/rchardet/codingstatemachine.rb', line 38 def reset @_mCurrentState = EStart end |