nsSBCSGroupProber Class Reference

#include <nsSBCSGroupProber.h>

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

Public Member Functions

 nsSBCSGroupProber ()
virtual ~nsSBCSGroupProber ()
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_SBCS_PROBERS]
PRBool mIsActive [NUM_OF_SBCS_PROBERS]
PRInt32 mBestGuess
PRUint32 mActiveNum

Detailed Description

Definition at line 46 of file nsSBCSGroupProber.h.


Constructor & Destructor Documentation

nsSBCSGroupProber::nsSBCSGroupProber (  ) 

Definition at line 47 of file nsSBCSGroupProber.cpp.

References Ibm855Model, Ibm866Model, Koi8rModel, Latin5BulgarianModel, Latin5Model, Latin7Model, MacCyrillicModel, mProbers, PR_FALSE, PR_TRUE, Reset(), nsHebrewProber::SetModelProbers(), Win1251BulgarianModel, Win1251Model, Win1253Model, and Win1255Model.

00048 {
00049   mProbers[0] = new nsSingleByteCharSetProber(&Win1251Model);
00050   mProbers[1] = new nsSingleByteCharSetProber(&Koi8rModel);
00051   mProbers[2] = new nsSingleByteCharSetProber(&Latin5Model);
00052   mProbers[3] = new nsSingleByteCharSetProber(&MacCyrillicModel);
00053   mProbers[4] = new nsSingleByteCharSetProber(&Ibm866Model);
00054   mProbers[5] = new nsSingleByteCharSetProber(&Ibm855Model);
00055   mProbers[6] = new nsSingleByteCharSetProber(&Latin7Model);
00056   mProbers[7] = new nsSingleByteCharSetProber(&Win1253Model);
00057   mProbers[8] = new nsSingleByteCharSetProber(&Latin5BulgarianModel);
00058   mProbers[9] = new nsSingleByteCharSetProber(&Win1251BulgarianModel);
00059 
00060   nsHebrewProber *hebprober = new nsHebrewProber();
00061   // Notice: Any change in these indexes - 10,11,12 must be reflected
00062   // in the code below as well.
00063   mProbers[10] = hebprober;
00064   mProbers[11] = new nsSingleByteCharSetProber(&Win1255Model, PR_FALSE, hebprober); // Logical Hebrew
00065   mProbers[12] = new nsSingleByteCharSetProber(&Win1255Model, PR_TRUE, hebprober); // Visual Hebrew
00066   // Tell the Hebrew prober about the logical and visual probers
00067   if (mProbers[10] && mProbers[11] && mProbers[12]) // all are not null
00068   {
00069     hebprober->SetModelProbers(mProbers[11], mProbers[12]);
00070   }
00071   else // One or more is null. avoid any Hebrew probing, null them all
00072   {
00073     for (PRUint32 i = 10; i <= 12; ++i)
00074     { 
00075       delete mProbers[i]; 
00076       mProbers[i] = 0; 
00077     }
00078   }
00079 
00080   // disable latin2 before latin1 is available, otherwise all latin1 
00081   // will be detected as latin2 because of their similarity.
00082   //mProbers[10] = new nsSingleByteCharSetProber(&Latin2HungarianModel);
00083   //mProbers[11] = new nsSingleByteCharSetProber(&Win1250HungarianModel);
00084 
00085   Reset();
00086 }

Here is the call graph for this function:

nsSBCSGroupProber::~nsSBCSGroupProber (  )  [virtual]

Definition at line 88 of file nsSBCSGroupProber.cpp.

References mProbers, and NUM_OF_SBCS_PROBERS.

00089 {
00090   for (PRUint32 i = 0; i < NUM_OF_SBCS_PROBERS; i++)
00091   {
00092     delete mProbers[i];
00093   }
00094 }


Member Function Documentation

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

Implements nsCharSetProber.

Definition at line 97 of file nsSBCSGroupProber.cpp.

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

00098 {
00099   //if we have no answer yet
00100   if (mBestGuess == -1)
00101   {
00102     GetConfidence();
00103     //no charset seems positive
00104     if (mBestGuess == -1)
00105       //we will use default.
00106       mBestGuess = 0;
00107   }
00108   return mProbers[mBestGuess]->GetCharSetName();
00109 }

Here is the call graph for this function:

float nsSBCSGroupProber::GetConfidence ( void   )  [virtual]

Implements nsCharSetProber.

Definition at line 178 of file nsSBCSGroupProber.cpp.

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

Referenced by GetCharSetName().

00179 {
00180   PRUint32 i;
00181   float bestConf = 0.0, cf;
00182 
00183   switch (mState)
00184   {
00185   case eFoundIt:
00186     return (float)0.99; //sure yes
00187   case eNotMe:
00188     return (float)0.01;  //sure no
00189   default:
00190     for (i = 0; i < NUM_OF_SBCS_PROBERS; i++)
00191     {
00192       if (!mIsActive[i])
00193         continue;
00194       cf = mProbers[i]->GetConfidence();
00195       if (bestConf < cf)
00196       {
00197         bestConf = cf;
00198         mBestGuess = i;
00199       }
00200     }
00201   }
00202   return bestConf;
00203 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements nsCharSetProber.

Definition at line 52 of file nsSBCSGroupProber.h.

References mState.

00052 {return mState;};

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

Implements nsCharSetProber.

Definition at line 130 of file nsSBCSGroupProber.cpp.

References eFoundIt, eNotMe, nsCharSetProber::FilterWithoutEnglishLetters(), nsCharSetProber::HandleData(), mActiveNum, mBestGuess, mIsActive, mProbers, mState, NUM_OF_SBCS_PROBERS, PR_FALSE, and PR_FREEIF.

00131 {
00132   nsProbingState st;
00133   PRUint32 i;
00134   char *newBuf1 = 0;
00135   PRUint32 newLen1 = 0;
00136 
00137   //apply filter to original buffer, and we got new buffer back
00138   //depend on what script it is, we will feed them the new buffer 
00139   //we got after applying proper filter
00140   //this is done without any consideration to KeepEnglishLetters
00141   //of each prober since as of now, there are no probers here which
00142   //recognize languages with English characters.
00143   if (!FilterWithoutEnglishLetters(aBuf, aLen, &newBuf1, newLen1))
00144     goto done;
00145   
00146   if (newLen1 == 0)
00147     goto done; // Nothing to see here, move on.
00148 
00149   for (i = 0; i < NUM_OF_SBCS_PROBERS; i++)
00150   {
00151      if (!mIsActive[i])
00152        continue;
00153      st = mProbers[i]->HandleData(newBuf1, newLen1);
00154      if (st == eFoundIt)
00155      {
00156        mBestGuess = i;
00157        mState = eFoundIt;
00158        break;
00159      }
00160      else if (st == eNotMe)
00161      {
00162        mIsActive[i] = PR_FALSE;
00163        mActiveNum--;
00164        if (mActiveNum <= 0)
00165        {
00166          mState = eNotMe;
00167          break;
00168        }
00169      }
00170   }
00171 
00172 done:
00173   PR_FREEIF(newBuf1);
00174 
00175   return mState;
00176 }

Here is the call graph for this function:

void nsSBCSGroupProber::Reset ( void   )  [virtual]

Implements nsCharSetProber.

Definition at line 111 of file nsSBCSGroupProber.cpp.

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

Referenced by nsSBCSGroupProber().

00112 {
00113   mActiveNum = 0;
00114   for (PRUint32 i = 0; i < NUM_OF_SBCS_PROBERS; i++)
00115   {
00116     if (mProbers[i]) // not null
00117     {
00118       mProbers[i]->Reset();
00119       mIsActive[i] = PR_TRUE;
00120       ++mActiveNum;
00121     }
00122     else
00123       mIsActive[i] = PR_FALSE;
00124   }
00125   mBestGuess = -1;
00126   mState = eDetecting;
00127 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements nsCharSetProber.

Definition at line 55 of file nsSBCSGroupProber.h.

00055 {};


Field Documentation

Definition at line 66 of file nsSBCSGroupProber.h.

Referenced by HandleData(), and Reset().

Definition at line 65 of file nsSBCSGroupProber.h.

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

PRBool nsSBCSGroupProber::mIsActive[NUM_OF_SBCS_PROBERS] [protected]

Definition at line 64 of file nsSBCSGroupProber.h.

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

nsCharSetProber* nsSBCSGroupProber::mProbers[NUM_OF_SBCS_PROBERS] [protected]

Definition at line 55 of file nsSBCSGroupProber.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