nsMBCSGroupProber Class Reference

#include <nsMBCSGroupProber.h>

Inheritance diagram for nsMBCSGroupProber:
Inheritance graph
[legend]
Collaboration diagram for nsMBCSGroupProber:
Collaboration graph
[legend]

Public Member Functions

 nsMBCSGroupProber ()
virtual ~nsMBCSGroupProber ()
nsProbingState HandleData (const char *aBuf, PRUint32 aLen)
const char * GetCharSetName ()
nsProbingState GetState (void)
void Reset (void)
float GetConfidence (void)
void SetOpion ()

Protected Attributes

nsProbingState mState
nsCharSetProbermProbers [NUM_OF_PROBERS]
PRBool mIsActive [NUM_OF_PROBERS]
PRInt32 mBestGuess
PRUint32 mActiveNum

Detailed Description

Definition at line 51 of file nsMBCSGroupProber.h.


Constructor & Destructor Documentation

nsMBCSGroupProber::nsMBCSGroupProber (  ) 

Definition at line 57 of file nsMBCSGroupProber.cpp.

References mProbers, and Reset().

00058 {
00059   mProbers[0] = new nsUTF8Prober();
00060   mProbers[1] = new nsSJISProber();
00061   mProbers[2] = new nsEUCJPProber();
00062   mProbers[3] = new nsGB18030Prober();
00063   mProbers[4] = new nsEUCKRProber();
00064   mProbers[5] = new nsBig5Prober();
00065   mProbers[6] = new nsEUCTWProber();
00066   Reset();
00067 }

Here is the call graph for this function:

nsMBCSGroupProber::~nsMBCSGroupProber (  )  [virtual]

Definition at line 69 of file nsMBCSGroupProber.cpp.

References mProbers, and NUM_OF_PROBERS.

00070 {
00071   for (PRUint32 i = 0; i < NUM_OF_PROBERS; i++)
00072   {
00073     delete mProbers[i];
00074   }
00075 }


Member Function Documentation

const char * nsMBCSGroupProber::GetCharSetName (  )  [virtual]

Implements nsCharSetProber.

Definition at line 77 of file nsMBCSGroupProber.cpp.

References nsCharSetProber::GetCharSetName(), GetConfidence(), mBestGuess, and mProbers.

00078 {
00079   if (mBestGuess == -1)
00080   {
00081     GetConfidence();
00082     if (mBestGuess == -1)
00083       mBestGuess = 0;
00084   }
00085   return mProbers[mBestGuess]->GetCharSetName();
00086 }

Here is the call graph for this function:

float nsMBCSGroupProber::GetConfidence ( void   )  [virtual]

Implements nsCharSetProber.

Definition at line 164 of file nsMBCSGroupProber.cpp.

References eFoundIt, eNotMe, nsCharSetProber::GetConfidence(), mBestGuess, mIsActive, mProbers, mState, and NUM_OF_PROBERS.

Referenced by GetCharSetName().

00165 {
00166   PRUint32 i;
00167   float bestConf = 0.0, cf;
00168 
00169   switch (mState)
00170   {
00171   case eFoundIt:
00172     return (float)0.99;
00173   case eNotMe:
00174     return (float)0.01;
00175   default:
00176     for (i = 0; i < NUM_OF_PROBERS; i++)
00177     {
00178       if (!mIsActive[i])
00179         continue;
00180       cf = mProbers[i]->GetConfidence();
00181       if (bestConf < cf)
00182       {
00183         bestConf = cf;
00184         mBestGuess = i;
00185       }
00186     }
00187   }
00188   return bestConf;
00189 }

Here is the call graph for this function:

Here is the caller graph for this function:

nsProbingState nsMBCSGroupProber::GetState ( void   )  [inline, virtual]

Implements nsCharSetProber.

Definition at line 57 of file nsMBCSGroupProber.h.

References mState.

00057 {return mState;};

nsProbingState nsMBCSGroupProber::HandleData ( const char *  aBuf,
PRUint32  aLen 
) [virtual]

Implements nsCharSetProber.

Definition at line 106 of file nsMBCSGroupProber.cpp.

References eFoundIt, eNotMe, nsCharSetProber::HandleData(), mActiveNum, mBestGuess, mIsActive, mProbers, mState, NUM_OF_PROBERS, PR_FALSE, PR_FREEIF, PR_Malloc, and PR_TRUE.

00107 {
00108   nsProbingState st;
00109   PRUint32 i;
00110 
00111   //do filtering to reduce load to probers
00112   char *highbyteBuf;
00113   char *hptr;
00114   PRBool keepNext = PR_TRUE;   //assume previous is not ascii, it will do no harm except add some noise
00115   hptr = highbyteBuf = (char*)PR_Malloc(aLen);
00116   if (!hptr)
00117       return mState;
00118   for (i = 0; i < aLen; i++)
00119   {
00120     if (aBuf[i] & 0x80)
00121     {
00122       *hptr++ = aBuf[i];
00123       keepNext = PR_TRUE;
00124     }
00125     else
00126     {
00127       //if previous is highbyte, keep this even it is a ASCII
00128       if (keepNext)
00129       {
00130           *hptr++ = aBuf[i];
00131           keepNext = PR_FALSE;
00132       }
00133     }
00134   }
00135 
00136   for (i = 0; i < NUM_OF_PROBERS; i++)
00137   {
00138      if (!mIsActive[i])
00139        continue;
00140      st = mProbers[i]->HandleData(highbyteBuf, hptr - highbyteBuf);
00141      if (st == eFoundIt)
00142      {
00143        mBestGuess = i;
00144        mState = eFoundIt;
00145        break;
00146      }
00147      else if (st == eNotMe)
00148      {
00149        mIsActive[i] = PR_FALSE;
00150        mActiveNum--;
00151        if (mActiveNum <= 0)
00152        {
00153          mState = eNotMe;
00154          break;
00155        }
00156      }
00157   }
00158 
00159   PR_FREEIF(highbyteBuf);
00160 
00161   return mState;
00162 }

Here is the call graph for this function:

void nsMBCSGroupProber::Reset ( void   )  [virtual]

Implements nsCharSetProber.

Definition at line 88 of file nsMBCSGroupProber.cpp.

References eDetecting, mActiveNum, mBestGuess, mIsActive, mProbers, mState, NUM_OF_PROBERS, PR_FALSE, PR_TRUE, and nsCharSetProber::Reset().

Referenced by nsMBCSGroupProber().

00089 {
00090   mActiveNum = 0;
00091   for (PRUint32 i = 0; i < NUM_OF_PROBERS; i++)
00092   {
00093     if (mProbers[i])
00094     {
00095       mProbers[i]->Reset();
00096       mIsActive[i] = PR_TRUE;
00097       ++mActiveNum;
00098     }
00099     else
00100       mIsActive[i] = PR_FALSE;
00101   }
00102   mBestGuess = -1;
00103   mState = eDetecting;
00104 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsMBCSGroupProber::SetOpion (  )  [inline, virtual]

Implements nsCharSetProber.

Definition at line 60 of file nsMBCSGroupProber.h.

00060 {};


Field Documentation

Definition at line 71 of file nsMBCSGroupProber.h.

Referenced by HandleData(), and Reset().

Definition at line 70 of file nsMBCSGroupProber.h.

Referenced by GetCharSetName(), GetConfidence(), HandleData(), and Reset().

PRBool nsMBCSGroupProber::mIsActive[NUM_OF_PROBERS] [protected]

Definition at line 69 of file nsMBCSGroupProber.h.

Referenced by GetConfidence(), HandleData(), and Reset().

nsCharSetProber* nsMBCSGroupProber::mProbers[NUM_OF_PROBERS] [protected]

Definition at line 60 of file nsMBCSGroupProber.h.

Referenced by GetConfidence(), GetState(), HandleData(), and Reset().


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208