extensions/universalchardet/src/base/nsBig5Prober.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extensions/universalchardet/src/base/nsBig5Prober.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsBig5Prober.h"
    1.10 +#include "nsDebug.h"
    1.11 +
    1.12 +void  nsBig5Prober::Reset(void)
    1.13 +{
    1.14 +  mCodingSM->Reset(); 
    1.15 +  mState = eDetecting;
    1.16 +  mDistributionAnalyser.Reset(mIsPreferredLanguage);
    1.17 +}
    1.18 +
    1.19 +nsProbingState nsBig5Prober::HandleData(const char* aBuf, uint32_t aLen)
    1.20 +{
    1.21 +  NS_ASSERTION(aLen, "HandleData called with empty buffer");
    1.22 +  nsSMState codingState;
    1.23 +
    1.24 +  for (uint32_t i = 0; i < aLen; i++)
    1.25 +  {
    1.26 +    codingState = mCodingSM->NextState(aBuf[i]);
    1.27 +    if (codingState == eItsMe)
    1.28 +    {
    1.29 +      mState = eFoundIt;
    1.30 +      break;
    1.31 +    }
    1.32 +    if (codingState == eStart)
    1.33 +    {
    1.34 +      uint32_t charLen = mCodingSM->GetCurrentCharLen();
    1.35 +
    1.36 +      if (i == 0)
    1.37 +      {
    1.38 +        mLastChar[1] = aBuf[0];
    1.39 +        mDistributionAnalyser.HandleOneChar(mLastChar, charLen);
    1.40 +      }
    1.41 +      else
    1.42 +        mDistributionAnalyser.HandleOneChar(aBuf+i-1, charLen);
    1.43 +    }
    1.44 +  }
    1.45 +
    1.46 +  mLastChar[0] = aBuf[aLen-1];
    1.47 +
    1.48 +  if (mState == eDetecting)
    1.49 +    if (mDistributionAnalyser.GotEnoughData() && GetConfidence() > SHORTCUT_THRESHOLD)
    1.50 +      mState = eFoundIt;
    1.51 +
    1.52 +  return mState;
    1.53 +}
    1.54 +
    1.55 +float nsBig5Prober::GetConfidence(void)
    1.56 +{
    1.57 +  float distribCf = mDistributionAnalyser.GetConfidence();
    1.58 +
    1.59 +  return (float)distribCf;
    1.60 +}
    1.61 +

mercurial