Class CharDet::UTF8Prober
In: lib/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb
Parent: CharSetProber

Methods

Public Class methods

[Source]

# File lib/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb, line 33
    def initialize
      super()
      @_mCodingSM = CodingStateMachine.new(UTF8SMModel)
      reset()
    end

Public Instance methods

[Source]

# File lib/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb, line 49
    def feed(aBuf)
      aBuf.each_byte do |b|
        c = b.chr
        codingState = @_mCodingSM.next_state(c)
        if codingState == EError
          @_mState = ENotMe
          break
        elsif codingState == EItsMe
          @_mState = EFoundIt
          break
        elsif codingState == EStart
          if @_mCodingSM.get_current_charlen() >= 2
            @_mNumOfMBChar += 1
          end
        end
      end

      if get_state() == EDetecting
        if get_confidence() > SHORTCUT_THRESHOLD
          @_mState = EFoundIt
        end
      end

      return get_state()
    end

[Source]

# File lib/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb, line 45
    def get_charset_name
      return "utf-8"
    end

[Source]

# File lib/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb, line 75
    def get_confidence
      unlike = 0.99
      if @_mNumOfMBChar < 6
        for i in (0...@_mNumOfMBChar)
          unlike = unlike * ONE_CHAR_PROB
        end
        return 1.0 - unlike
      else
        return unlike
      end
    end

[Source]

# File lib/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb, line 39
    def reset
      super()
      @_mCodingSM.reset()
      @_mNumOfMBChar = 0
    end

[Validate]