Thu, 22 Jan 2015 13:21:57 +0100
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 "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 }