#include <nsEscCharsetProber.h>
Public Member Functions | |
nsEscCharSetProber (void) | |
virtual | ~nsEscCharSetProber (void) |
nsProbingState | HandleData (const char *aBuf, PRUint32 aLen) |
const char * | GetCharSetName () |
nsProbingState | GetState (void) |
void | Reset (void) |
float | GetConfidence (void) |
void | SetOpion () |
Protected Member Functions | |
void | GetDistribution (PRUint32 aCharLen, const char *aStr) |
Protected Attributes | |
nsCodingStateMachine * | mCodingSM [NUM_OF_ESC_CHARSETS] |
PRUint32 | mActiveSM |
nsProbingState | mState |
const char * | mDetectedCharset |
Definition at line 46 of file nsEscCharsetProber.h.
nsEscCharSetProber::nsEscCharSetProber | ( | void | ) |
Definition at line 41 of file nsEscCharsetProber.cpp.
References eDetecting, HZSMModel, ISO2022CNSMModel, ISO2022JPSMModel, ISO2022KRSMModel, mActiveSM, mCodingSM, mDetectedCharset, mState, nsnull, and NUM_OF_ESC_CHARSETS.
00042 { 00043 mCodingSM[0] = new nsCodingStateMachine(&HZSMModel); 00044 mCodingSM[1] = new nsCodingStateMachine(&ISO2022CNSMModel); 00045 mCodingSM[2] = new nsCodingStateMachine(&ISO2022JPSMModel); 00046 mCodingSM[3] = new nsCodingStateMachine(&ISO2022KRSMModel); 00047 mActiveSM = NUM_OF_ESC_CHARSETS; 00048 mState = eDetecting; 00049 mDetectedCharset = nsnull; 00050 }
nsEscCharSetProber::~nsEscCharSetProber | ( | void | ) | [virtual] |
Definition at line 52 of file nsEscCharsetProber.cpp.
References mCodingSM, and NUM_OF_ESC_CHARSETS.
00053 { 00054 for (PRUint32 i = 0; i < NUM_OF_ESC_CHARSETS; i++) 00055 delete mCodingSM[i]; 00056 }
const char* nsEscCharSetProber::GetCharSetName | ( | ) | [inline, virtual] |
Implements nsCharSetProber.
Definition at line 51 of file nsEscCharsetProber.h.
References mDetectedCharset.
00051 {return mDetectedCharset;};
float nsEscCharSetProber::GetConfidence | ( | void | ) | [inline, virtual] |
Implements nsCharSetProber.
Definition at line 54 of file nsEscCharsetProber.h.
void nsEscCharSetProber::GetDistribution | ( | PRUint32 | aCharLen, | |
const char * | aStr | |||
) | [protected] |
nsProbingState nsEscCharSetProber::GetState | ( | void | ) | [inline, virtual] |
Implements nsCharSetProber.
Definition at line 52 of file nsEscCharsetProber.h.
References mState.
00052 {return mState;};
nsProbingState nsEscCharSetProber::HandleData | ( | const char * | aBuf, | |
PRUint32 | aLen | |||
) | [virtual] |
Implements nsCharSetProber.
Definition at line 67 of file nsEscCharsetProber.cpp.
References eDetecting, eError, eFoundIt, eItsMe, eNotMe, nsCodingStateMachine::GetCodingStateMachine(), mActiveSM, mCodingSM, mDetectedCharset, mState, and nsCodingStateMachine::NextState().
00068 { 00069 nsSMState codingState; 00070 PRInt32 j; 00071 PRUint32 i; 00072 00073 for ( i = 0; i < aLen && mState == eDetecting; i++) 00074 { 00075 for (j = mActiveSM-1; j>= 0; j--) 00076 { 00077 //byte is feed to all active state machine 00078 codingState = mCodingSM[j]->NextState(aBuf[i]); 00079 if (codingState == eError) 00080 { 00081 //got negative answer for this state machine, make it inactive 00082 mActiveSM--; 00083 if (mActiveSM == 0) 00084 { 00085 mState = eNotMe; 00086 return mState; 00087 } 00088 else if (j != (PRInt32)mActiveSM) 00089 { 00090 nsCodingStateMachine* t; 00091 t = mCodingSM[mActiveSM]; 00092 mCodingSM[mActiveSM] = mCodingSM[j]; 00093 mCodingSM[j] = t; 00094 } 00095 } 00096 else if (codingState == eItsMe) 00097 { 00098 mState = eFoundIt; 00099 mDetectedCharset = mCodingSM[j]->GetCodingStateMachine(); 00100 return mState; 00101 } 00102 } 00103 } 00104 00105 return mState; 00106 }
void nsEscCharSetProber::Reset | ( | void | ) | [virtual] |
Implements nsCharSetProber.
Definition at line 58 of file nsEscCharsetProber.cpp.
References eDetecting, mActiveSM, mCodingSM, mDetectedCharset, mState, nsnull, and NUM_OF_ESC_CHARSETS.
00059 { 00060 mState = eDetecting; 00061 for (PRUint32 i = 0; i < NUM_OF_ESC_CHARSETS; i++) 00062 mCodingSM[i]->Reset(); 00063 mActiveSM = NUM_OF_ESC_CHARSETS; 00064 mDetectedCharset = nsnull; 00065 }
void nsEscCharSetProber::SetOpion | ( | ) | [inline, virtual] |
PRUint32 nsEscCharSetProber::mActiveSM [protected] |
Definition at line 61 of file nsEscCharsetProber.h.
Referenced by HandleData(), nsEscCharSetProber(), and Reset().
nsCodingStateMachine* nsEscCharSetProber::mCodingSM[NUM_OF_ESC_CHARSETS] [protected] |
Definition at line 60 of file nsEscCharsetProber.h.
Referenced by HandleData(), nsEscCharSetProber(), Reset(), and ~nsEscCharSetProber().
const char* nsEscCharSetProber::mDetectedCharset [protected] |
Definition at line 63 of file nsEscCharsetProber.h.
Referenced by GetCharSetName(), HandleData(), nsEscCharSetProber(), and Reset().
nsProbingState nsEscCharSetProber::mState [protected] |
Definition at line 62 of file nsEscCharsetProber.h.
Referenced by GetState(), HandleData(), nsEscCharSetProber(), and Reset().