extensions/universalchardet/src/base/nsEUCTWProber.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsEUCTWProber.h"
     7 #include "nsDebug.h"
     9 void  nsEUCTWProber::Reset(void)
    10 {
    11   mCodingSM->Reset(); 
    12   mState = eDetecting;
    13   mDistributionAnalyser.Reset(mIsPreferredLanguage);
    14   //mContextAnalyser.Reset();
    15 }
    17 nsProbingState nsEUCTWProber::HandleData(const char* aBuf, uint32_t aLen)
    18 {
    19   NS_ASSERTION(aLen, "HandleData called with empty buffer");
    20   nsSMState codingState;
    22   for (uint32_t i = 0; i < aLen; i++)
    23   {
    24     codingState = mCodingSM->NextState(aBuf[i]);
    25     if (codingState == eItsMe)
    26     {
    27       mState = eFoundIt;
    28       break;
    29     }
    30     if (codingState == eStart)
    31     {
    32       uint32_t charLen = mCodingSM->GetCurrentCharLen();
    34       if (i == 0)
    35       {
    36         mLastChar[1] = aBuf[0];
    37         mDistributionAnalyser.HandleOneChar(mLastChar, charLen);
    38       }
    39       else
    40         mDistributionAnalyser.HandleOneChar(aBuf+i-1, charLen);
    41     }
    42   }
    44   mLastChar[0] = aBuf[aLen-1];
    46   if (mState == eDetecting)
    47     if (mDistributionAnalyser.GotEnoughData() && GetConfidence() > SHORTCUT_THRESHOLD)
    48       mState = eFoundIt;
    49 //    else
    50 //      mDistributionAnalyser.HandleData(aBuf, aLen);
    52   return mState;
    53 }
    55 float nsEUCTWProber::GetConfidence(void)
    56 {
    57   float distribCf = mDistributionAnalyser.GetConfidence();
    59   return (float)distribCf;
    60 }

mercurial