|
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/. */ |
|
5 |
|
6 #include "nsEUCKRProber.h" |
|
7 #include "nsDebug.h" |
|
8 |
|
9 void nsEUCKRProber::Reset(void) |
|
10 { |
|
11 mCodingSM->Reset(); |
|
12 mState = eDetecting; |
|
13 mDistributionAnalyser.Reset(mIsPreferredLanguage); |
|
14 //mContextAnalyser.Reset(); |
|
15 } |
|
16 |
|
17 nsProbingState nsEUCKRProber::HandleData(const char* aBuf, uint32_t aLen) |
|
18 { |
|
19 NS_ASSERTION(aLen, "HandleData called with empty buffer"); |
|
20 nsSMState codingState; |
|
21 |
|
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(); |
|
33 |
|
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 } |
|
43 |
|
44 mLastChar[0] = aBuf[aLen-1]; |
|
45 |
|
46 if (mState == eDetecting) |
|
47 if (mDistributionAnalyser.GotEnoughData() && GetConfidence() > SHORTCUT_THRESHOLD) |
|
48 mState = eFoundIt; |
|
49 // else |
|
50 // mDistributionAnalyser.HandleData(aBuf, aLen); |
|
51 |
|
52 return mState; |
|
53 } |
|
54 |
|
55 float nsEUCKRProber::GetConfidence(void) |
|
56 { |
|
57 float distribCf = mDistributionAnalyser.GetConfidence(); |
|
58 |
|
59 return (float)distribCf; |
|
60 } |
|
61 |