#include <nsLatin1Prober.h>
Public Member Functions | |
nsLatin1Prober (void) | |
virtual | ~nsLatin1Prober (void) |
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 |
char | mLastCharClass |
PRUint32 | mFreqCounter [FREQ_CAT_NUM] |
Definition at line 46 of file nsLatin1Prober.h.
nsLatin1Prober::nsLatin1Prober | ( | void | ) | [inline] |
Definition at line 48 of file nsLatin1Prober.h.
References Reset().
00048 {Reset();};
virtual nsLatin1Prober::~nsLatin1Prober | ( | void | ) | [inline, virtual] |
Definition at line 49 of file nsLatin1Prober.h.
const char* nsLatin1Prober::GetCharSetName | ( | ) | [inline, virtual] |
Implements nsCharSetProber.
Definition at line 51 of file nsLatin1Prober.h.
float nsLatin1Prober::GetConfidence | ( | void | ) | [virtual] |
Implements nsCharSetProber.
Definition at line 147 of file nsLatin1Prober.cpp.
References eNotMe, FREQ_CAT_NUM, mFreqCounter, and mState.
00148 { 00149 if (mState == eNotMe) 00150 return 0.01f; 00151 00152 float confidence; 00153 PRUint32 total = 0; 00154 for (PRInt32 i = 0; i < FREQ_CAT_NUM; i++) 00155 total += mFreqCounter[i]; 00156 00157 if(!total) 00158 confidence = 0.0f; 00159 else 00160 { 00161 confidence = mFreqCounter[3]*1.0f / total; 00162 confidence -= mFreqCounter[1]*20.0f/total; 00163 } 00164 00165 if (confidence < 0.0f) 00166 confidence = 0.0f; 00167 00168 // lower the confidence of latin1 so that other more accurate detector 00169 // can take priority. 00170 confidence *= 0.50f; 00171 00172 return confidence; 00173 }
nsProbingState nsLatin1Prober::GetState | ( | void | ) | [inline, virtual] |
Implements nsCharSetProber.
Definition at line 52 of file nsLatin1Prober.h.
References mState.
00052 {return mState;};
nsProbingState nsLatin1Prober::HandleData | ( | const char * | aBuf, | |
PRUint32 | aLen | |||
) | [virtual] |
Implements nsCharSetProber.
Definition at line 117 of file nsLatin1Prober.cpp.
References CLASS_NUM, eNotMe, nsCharSetProber::FilterWithEnglishLetters(), Latin1_CharToClass, Latin1ClassModel, mFreqCounter, mLastCharClass, mState, and PR_FREEIF.
00118 { 00119 char *newBuf1 = 0; 00120 PRUint32 newLen1 = 0; 00121 00122 if (!FilterWithEnglishLetters(aBuf, aLen, &newBuf1, newLen1)) { 00123 newBuf1 = (char*)aBuf; 00124 newLen1 = aLen; 00125 } 00126 00127 unsigned char charClass; 00128 unsigned char freq; 00129 for (PRUint32 i = 0; i < newLen1; i++) 00130 { 00131 charClass = Latin1_CharToClass[(unsigned char)newBuf1[i]]; 00132 freq = Latin1ClassModel[mLastCharClass*CLASS_NUM + charClass]; 00133 if (freq == 0) { 00134 mState = eNotMe; 00135 break; 00136 } 00137 mFreqCounter[freq]++; 00138 mLastCharClass = charClass; 00139 } 00140 00141 if (newBuf1 != aBuf) 00142 PR_FREEIF(newBuf1); 00143 00144 return mState; 00145 }
void nsLatin1Prober::Reset | ( | void | ) | [virtual] |
Implements nsCharSetProber.
Definition at line 108 of file nsLatin1Prober.cpp.
References eDetecting, FREQ_CAT_NUM, mFreqCounter, mLastCharClass, mState, and OTH.
Referenced by nsLatin1Prober().
00109 { 00110 mState = eDetecting; 00111 mLastCharClass = OTH; 00112 for (int i = 0; i < FREQ_CAT_NUM; i++) 00113 mFreqCounter[i] = 0; 00114 }
void nsLatin1Prober::SetOpion | ( | ) | [inline, virtual] |
PRUint32 nsLatin1Prober::mFreqCounter[FREQ_CAT_NUM] [protected] |
Definition at line 65 of file nsLatin1Prober.h.
Referenced by GetConfidence(), HandleData(), and Reset().
char nsLatin1Prober::mLastCharClass [protected] |
Definition at line 64 of file nsLatin1Prober.h.
Referenced by HandleData(), and Reset().
nsProbingState nsLatin1Prober::mState [protected] |
Definition at line 55 of file nsLatin1Prober.h.
Referenced by GetConfidence(), GetState(), HandleData(), and Reset().