#include <nsUTF8Prober.h>
Public Member Functions | |
nsUTF8Prober () | |
virtual | ~nsUTF8Prober () |
nsProbingState | HandleData (const char *aBuf, PRUint32 aLen) |
const char * | GetCharSetName () |
nsProbingState | GetState (void) |
void | Reset (void) |
float | GetConfidence (void) |
void | SetOpion () |
Protected Attributes | |
nsCodingStateMachine * | mCodingSM |
nsProbingState | mState |
PRUint32 | mNumOfMBChar |
Definition at line 44 of file nsUTF8Prober.h.
nsUTF8Prober::nsUTF8Prober | ( | ) | [inline] |
Definition at line 46 of file nsUTF8Prober.h.
References mCodingSM, mNumOfMBChar, Reset(), and UTF8SMModel.
00046 {mNumOfMBChar = 0; 00047 mCodingSM = new nsCodingStateMachine(&UTF8SMModel); 00048 Reset(); };
virtual nsUTF8Prober::~nsUTF8Prober | ( | ) | [inline, virtual] |
const char* nsUTF8Prober::GetCharSetName | ( | ) | [inline, virtual] |
float nsUTF8Prober::GetConfidence | ( | void | ) | [virtual] |
Implements nsCharSetProber.
Definition at line 79 of file nsUTF8Prober.cpp.
References mNumOfMBChar, and ONE_CHAR_PROB.
Referenced by HandleData().
00080 { 00081 float unlike = (float)0.99; 00082 00083 if (mNumOfMBChar < 6) 00084 { 00085 for (PRUint32 i = 0; i < mNumOfMBChar; i++) 00086 unlike *= ONE_CHAR_PROB; 00087 return (float)1.0 - unlike; 00088 } 00089 else 00090 return (float)0.99; 00091 }
nsProbingState nsUTF8Prober::GetState | ( | void | ) | [inline, virtual] |
Implements nsCharSetProber.
Definition at line 52 of file nsUTF8Prober.h.
References mState.
00052 {return mState;};
nsProbingState nsUTF8Prober::HandleData | ( | const char * | aBuf, | |
PRUint32 | aLen | |||
) | [virtual] |
Implements nsCharSetProber.
Definition at line 47 of file nsUTF8Prober.cpp.
References eDetecting, eError, eFoundIt, eItsMe, eNotMe, eStart, GetConfidence(), nsCodingStateMachine::GetCurrentCharLen(), mCodingSM, mNumOfMBChar, mState, nsCodingStateMachine::NextState(), and SHORTCUT_THRESHOLD.
00048 { 00049 nsSMState codingState; 00050 00051 for (PRUint32 i = 0; i < aLen; i++) 00052 { 00053 codingState = mCodingSM->NextState(aBuf[i]); 00054 if (codingState == eError) 00055 { 00056 mState = eNotMe; 00057 break; 00058 } 00059 if (codingState == eItsMe) 00060 { 00061 mState = eFoundIt; 00062 break; 00063 } 00064 if (codingState == eStart) 00065 { 00066 if (mCodingSM->GetCurrentCharLen() >= 2) 00067 mNumOfMBChar++; 00068 } 00069 } 00070 00071 if (mState == eDetecting) 00072 if (GetConfidence() > SHORTCUT_THRESHOLD) 00073 mState = eFoundIt; 00074 return mState; 00075 }
void nsUTF8Prober::Reset | ( | void | ) | [virtual] |
Implements nsCharSetProber.
Definition at line 40 of file nsUTF8Prober.cpp.
References eDetecting, mCodingSM, mNumOfMBChar, mState, and nsCodingStateMachine::Reset().
Referenced by nsUTF8Prober().
00041 { 00042 mCodingSM->Reset(); 00043 mNumOfMBChar = 0; 00044 mState = eDetecting; 00045 }
void nsUTF8Prober::SetOpion | ( | ) | [inline, virtual] |
nsCodingStateMachine* nsUTF8Prober::mCodingSM [protected] |
Definition at line 55 of file nsUTF8Prober.h.
Referenced by HandleData(), nsUTF8Prober(), Reset(), and ~nsUTF8Prober().
PRUint32 nsUTF8Prober::mNumOfMBChar [protected] |
Definition at line 60 of file nsUTF8Prober.h.
Referenced by GetConfidence(), HandleData(), nsUTF8Prober(), and Reset().
nsProbingState nsUTF8Prober::mState [protected] |
Definition at line 59 of file nsUTF8Prober.h.
Referenced by GetState(), HandleData(), and Reset().