diff -r 000000000000 -r 6474c204b198 extensions/universalchardet/src/base/nsEUCKRProber.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/universalchardet/src/base/nsEUCKRProber.cpp Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsEUCKRProber.h" +#include "nsDebug.h" + +void nsEUCKRProber::Reset(void) +{ + mCodingSM->Reset(); + mState = eDetecting; + mDistributionAnalyser.Reset(mIsPreferredLanguage); + //mContextAnalyser.Reset(); +} + +nsProbingState nsEUCKRProber::HandleData(const char* aBuf, uint32_t aLen) +{ + NS_ASSERTION(aLen, "HandleData called with empty buffer"); + nsSMState codingState; + + for (uint32_t i = 0; i < aLen; i++) + { + codingState = mCodingSM->NextState(aBuf[i]); + if (codingState == eItsMe) + { + mState = eFoundIt; + break; + } + if (codingState == eStart) + { + uint32_t charLen = mCodingSM->GetCurrentCharLen(); + + if (i == 0) + { + mLastChar[1] = aBuf[0]; + mDistributionAnalyser.HandleOneChar(mLastChar, charLen); + } + else + mDistributionAnalyser.HandleOneChar(aBuf+i-1, charLen); + } + } + + mLastChar[0] = aBuf[aLen-1]; + + if (mState == eDetecting) + if (mDistributionAnalyser.GotEnoughData() && GetConfidence() > SHORTCUT_THRESHOLD) + mState = eFoundIt; +// else +// mDistributionAnalyser.HandleData(aBuf, aLen); + + return mState; +} + +float nsEUCKRProber::GetConfidence(void) +{ + float distribCf = mDistributionAnalyser.GetConfidence(); + + return (float)distribCf; +} +