Class: CharDet::EscCharSetProber

Inherits:
CharSetProber show all
Defined in:
lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb

Instance Attribute Summary

Attributes inherited from CharSetProber

#active

Instance Method Summary collapse

Methods inherited from CharSetProber

#filter_high_bit_only, #filter_with_english_letters, #filter_without_english_letters, #get_state

Constructor Details

#initializeEscCharSetProber

Returns a new instance of EscCharSetProber.



31
32
33
34
35
36
37
38
# File 'lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb', line 31

def initialize
  super()
  @_mCodingSM = [ CodingStateMachine.new(HZSMModel),
                  CodingStateMachine.new(ISO2022CNSMModel),
                  CodingStateMachine.new(ISO2022JPSMModel),
                  CodingStateMachine.new(ISO2022KRSMModel)  ]
  reset()
end

Instance Method Details

#feed(aBuf) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb', line 63

def feed(aBuf)
  aBuf.each_byte do |b|
    c = b.chr
    for codingSM in @_mCodingSM
      next unless codingSM
      next unless codingSM.active
      codingState = codingSM.next_state(c)
      if codingState == EError
        codingSM.active = false
        @_mActiveSM -= 1
        if @_mActiveSM <= 0
          @_mState = ENotMe
          return get_state()
        end
      elsif codingState == EItsMe
        @_mState = EFoundIt
        @_mDetectedCharset = codingSM.get_coding_state_machine()
        return get_state()
      end
    end
  end
  return get_state()

end

#get_charset_nameObject



51
52
53
# File 'lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb', line 51

def get_charset_name
  return @_mDetectedCharset
end

#get_confidenceObject



55
56
57
58
59
60
61
# File 'lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb', line 55

def get_confidence
  if @_mDetectedCharset
    return 0.99
  else
    return 0.00
  end
end

#resetObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb', line 40

def reset
  super()
  for codingSM in @_mCodingSM
    next if not codingSM
    codingSM.active = true
    codingSM.reset()
  end
  @_mActiveSM = @_mCodingSM.length
  @_mDetectedCharset = nil
end