<s> from . import constants <EOL> from . charsetprober import CharSetProber <EOL> from . codingstatemachine import CodingStateMachine <EOL> from . mbcssm import UTF8SMModel <EOL> ONE_CHAR_PROB = <NUM_LIT:0.5> <EOL> class UTF8Prober ( CharSetProber ) : <EOL> def __init__ ( self ) : <EOL> CharSetProber . __init__ ( self ) <EOL> self . _mCodingSM = CodingStateMachine ( UTF8SMModel ) <EOL> self . reset ( ) <EOL> def reset ( self ) : <EOL> CharSetProber . reset ( self ) <EOL> self . _mCodingSM . reset ( ) <EOL> self . _mNumOfMBChar = <NUM_LIT:0> <EOL> def get_charset_name ( self ) : <EOL> return "<STR_LIT:utf-8>" <EOL> def feed ( self , aBuf ) : <EOL> for c in aBuf : <EOL> codingState = self . _mCodingSM . next_state ( c ) <EOL> if codingState == constants . eError : <EOL> self . _mState = constants . eNotMe <EOL> break <EOL> elif codingState == constants . eItsMe : <EOL> self . _mState = constants . eFoundIt <EOL> break <EOL> elif codingState == constants . eStart : <EOL> if self . _mCodingSM . get_current_charlen ( ) >= <NUM_LIT:2> : <EOL> self . _mNumOfMBChar += <NUM_LIT:1> <EOL> if self . get_state ( ) == constants . eDetecting : <EOL> if self . get_confidence ( ) > constants . SHORTCUT_THRESHOLD : <EOL> self . _mState = constants . eFoundIt <EOL> return self . get_state ( ) <EOL> def get_confidence ( self ) : <EOL> unlike = <NUM_LIT> <EOL> if self . _mNumOfMBChar < <NUM_LIT:6> : <EOL> for i in range ( <NUM_LIT:0> , self . _mNumOfMBChar ) : <EOL> unlike = unlike * ONE_CHAR_PROB <EOL> return <NUM_LIT:1.0> - unlike <EOL> else : <EOL> return unlike </s>
