Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes | Private Attributes
nsBaseStatis Class Reference
Inheritance diagram for nsBaseStatis:
Inheritance graph
[legend]
Collaboration diagram for nsBaseStatis:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsBaseStatis (unsigned char aL, unsigned char aH, float aR)
virtual ~nsBaseStatis ()
virtual PRBool HandleData (const char *aBuf, PRUint32 aLen)
virtual void DataEnd ()
virtual void Report ()

Protected Attributes

unsigned char mLWordHi
unsigned char mLWordLo

Private Attributes

PRUint32 mNumOf2Bytes
PRUint32 mNumOfLChar
PRUint32 mNumOfLWord
PRUint32 mLWordLength
PRUint32 mLWordLen [10]
float mR
PRBool mTailByte
PRBool mLastLChar

Detailed Description

Definition at line 61 of file DetectCharset.cpp.


Constructor & Destructor Documentation

nsBaseStatis::nsBaseStatis ( unsigned char  aL,
unsigned char  aH,
float  aR 
)

Definition at line 81 of file DetectCharset.cpp.

{
    mNumOf2Bytes = mNumOfLWord = mLWordLength = mNumOfLChar= 0;
    mTailByte = mLastLChar = PR_FALSE;
    for(PRUint32 i =0;i < 20; i++)
       mLWordLen[i] = 0;
    mLWordHi = aH;
    mLWordLo = aL;
    mR = aR;
}
virtual nsBaseStatis::~nsBaseStatis ( ) [inline, virtual]

Definition at line 64 of file DetectCharset.cpp.

{};

Member Function Documentation

void nsBaseStatis::DataEnd ( void  ) [virtual]

Implements nsStatis.

Definition at line 129 of file DetectCharset.cpp.

{
    if(mLastLChar) {
      mNumOfLWord++;
      mLWordLen[ (mLWordLength > 10) ? 9 : (mLWordLength-1)]++;
    }
}
PRBool nsBaseStatis::HandleData ( const char *  aBuf,
PRUint32  aLen 
) [virtual]

Implements nsStatis.

Definition at line 91 of file DetectCharset.cpp.

{
    for(PRUint32 i=0; i < aLen; i++)
    {
       if(mTailByte)
          mTailByte = PR_FALSE;
       else 
       {
          mTailByte = (0x80 == ( aBuf[i] & 0x80));
          if(mTailByte) 
          {
             mNumOf2Bytes++;
             unsigned char a = (unsigned char) aBuf[i];
             PRBool thisLChar = (( mLWordLo <= a) && (a <= mLWordHi));
             if(thisLChar)
             {
                mNumOfLChar++;
                mLWordLength++;
             } else {
                if(mLastLChar) {
                  mNumOfLWord++;
                  mLWordLen[ (mLWordLength > 10) ? 9 : (mLWordLength-1)]++;
                  mLWordLength =0 ;
                }
             }
             mLastLChar = thisLChar;
          } else {
             if(mLastLChar) {
                mNumOfLWord++;
                mLWordLen[ (mLWordLength > 10) ? 9 : (mLWordLength-1)]++;
                mLWordLength =0 ;
                mLastLChar = PR_FALSE;
             }
          }
       }
    }
    return PR_TRUE;
}
void nsBaseStatis::Report ( ) [virtual]

Implements nsStatis.

Definition at line 136 of file DetectCharset.cpp.

{
    if(mNumOf2Bytes > 0)
    {
/*
      printf("LChar Ratio = %d : %d ( %5.3f)\n", 
                         mNumOfLChar,
                         mNumOf2Bytes,
                        ((float)mNumOfLChar / (float)mNumOf2Bytes) * 100);
*/
      float rate = (float) mNumOfLChar / (float) mNumOf2Bytes;
      float delta = (rate - mR) / mR;
      delta *= delta * 1000;
#ifdef EXPERIMENT
      printf("Exp = %f \n",delta);
#endif
    }
    
/*

    if(mNumOfLChar > 0)
      printf("LWord Word = %d : %d (%5.3f)\n", 
                         mNumOfLWord,
                         mNumOfLChar,
                        ((float)mNumOfLWord / (float)mNumOfLChar) * 100);
    if(mNumOfLWord > 0)
    {
      PRUint32 ac =0;
      for(PRUint32 i=0;i<10;i++)
      {
       ac += mLWordLen[i];
       printf("LWord Word Length[%d]= %d -> %5.3f%% %5.3f%%\n", i+1, 
           mLWordLen[i],
           (((float)mLWordLen[i] / (float)mNumOfLWord) * 100),
           (((float)ac / (float)mNumOfLWord) * 100));
      }
    }
*/
}

Member Data Documentation

Definition at line 79 of file DetectCharset.cpp.

unsigned char nsBaseStatis::mLWordHi [protected]

Definition at line 69 of file DetectCharset.cpp.

Definition at line 76 of file DetectCharset.cpp.

Definition at line 75 of file DetectCharset.cpp.

unsigned char nsBaseStatis::mLWordLo [protected]

Definition at line 70 of file DetectCharset.cpp.

Definition at line 72 of file DetectCharset.cpp.

Definition at line 73 of file DetectCharset.cpp.

Definition at line 74 of file DetectCharset.cpp.

float nsBaseStatis::mR [private]

Definition at line 77 of file DetectCharset.cpp.

Definition at line 78 of file DetectCharset.cpp.


The documentation for this class was generated from the following file: