extensions/universalchardet/src/base/nsEUCKRProber.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extensions/universalchardet/src/base/nsEUCKRProber.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     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 "nsEUCKRProber.h"
    1.10 +#include "nsDebug.h"
    1.11 +
    1.12 +void  nsEUCKRProber::Reset(void)
    1.13 +{
    1.14 +  mCodingSM->Reset(); 
    1.15 +  mState = eDetecting;
    1.16 +  mDistributionAnalyser.Reset(mIsPreferredLanguage);
    1.17 +  //mContextAnalyser.Reset();
    1.18 +}
    1.19 +
    1.20 +nsProbingState nsEUCKRProber::HandleData(const char* aBuf, uint32_t aLen)
    1.21 +{
    1.22 +  NS_ASSERTION(aLen, "HandleData called with empty buffer");
    1.23 +  nsSMState codingState;
    1.24 +
    1.25 +  for (uint32_t i = 0; i < aLen; i++)
    1.26 +  {
    1.27 +    codingState = mCodingSM->NextState(aBuf[i]);
    1.28 +    if (codingState == eItsMe)
    1.29 +    {
    1.30 +      mState = eFoundIt;
    1.31 +      break;
    1.32 +    }
    1.33 +    if (codingState == eStart)
    1.34 +    {
    1.35 +      uint32_t charLen = mCodingSM->GetCurrentCharLen();
    1.36 +
    1.37 +      if (i == 0)
    1.38 +      {
    1.39 +        mLastChar[1] = aBuf[0];
    1.40 +        mDistributionAnalyser.HandleOneChar(mLastChar, charLen);
    1.41 +      }
    1.42 +      else
    1.43 +        mDistributionAnalyser.HandleOneChar(aBuf+i-1, charLen);
    1.44 +    }
    1.45 +  }
    1.46 +
    1.47 +  mLastChar[0] = aBuf[aLen-1];
    1.48 +
    1.49 +  if (mState == eDetecting)
    1.50 +    if (mDistributionAnalyser.GotEnoughData() && GetConfidence() > SHORTCUT_THRESHOLD)
    1.51 +      mState = eFoundIt;
    1.52 +//    else
    1.53 +//      mDistributionAnalyser.HandleData(aBuf, aLen);
    1.54 +
    1.55 +  return mState;
    1.56 +}
    1.57 +
    1.58 +float nsEUCKRProber::GetConfidence(void)
    1.59 +{
    1.60 +  float distribCf = mDistributionAnalyser.GetConfidence();
    1.61 +
    1.62 +  return (float)distribCf;
    1.63 +}
    1.64 +

mercurial