Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 }