extensions/universalchardet/src/base/nsBig5Prober.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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 "nsBig5Prober.h"
     7 #include "nsDebug.h"
     9 void  nsBig5Prober::Reset(void)
    10 {
    11   mCodingSM->Reset(); 
    12   mState = eDetecting;
    13   mDistributionAnalyser.Reset(mIsPreferredLanguage);
    14 }
    16 nsProbingState nsBig5Prober::HandleData(const char* aBuf, uint32_t aLen)
    17 {
    18   NS_ASSERTION(aLen, "HandleData called with empty buffer");
    19   nsSMState codingState;
    21   for (uint32_t i = 0; i < aLen; i++)
    22   {
    23     codingState = mCodingSM->NextState(aBuf[i]);
    24     if (codingState == eItsMe)
    25     {
    26       mState = eFoundIt;
    27       break;
    28     }
    29     if (codingState == eStart)
    30     {
    31       uint32_t charLen = mCodingSM->GetCurrentCharLen();
    33       if (i == 0)
    34       {
    35         mLastChar[1] = aBuf[0];
    36         mDistributionAnalyser.HandleOneChar(mLastChar, charLen);
    37       }
    38       else
    39         mDistributionAnalyser.HandleOneChar(aBuf+i-1, charLen);
    40     }
    41   }
    43   mLastChar[0] = aBuf[aLen-1];
    45   if (mState == eDetecting)
    46     if (mDistributionAnalyser.GotEnoughData() && GetConfidence() > SHORTCUT_THRESHOLD)
    47       mState = eFoundIt;
    49   return mState;
    50 }
    52 float nsBig5Prober::GetConfidence(void)
    53 {
    54   float distribCf = mDistributionAnalyser.GetConfidence();
    56   return (float)distribCf;
    57 }

mercurial