KCodecs

nsBig5Prober.cpp
1/* -*- C++ -*-
2 SPDX-FileCopyrightText: 1998 Netscape Communications Corporation <developer@mozilla.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include "nsBig5Prober.h"
8
9namespace kencodingprober
10{
11void nsBig5Prober::Reset(void)
12{
13 mCodingSM->Reset();
14 mState = eDetecting;
15 mDistributionAnalyser.Reset();
16}
17
18nsProbingState nsBig5Prober::HandleData(const char *aBuf, unsigned int aLen)
19{
20 if (aLen == 0) {
21 return mState;
22 }
23
24 for (unsigned int i = 0; i < aLen; i++) {
25 const nsSMState codingState = mCodingSM->NextState(aBuf[i]);
26 if (codingState == eError) {
27 mState = eNotMe;
28 break;
29 }
30 if (codingState == eItsMe) {
31 mState = eFoundIt;
32 break;
33 }
34 if (codingState == eStart) {
35 unsigned int charLen = mCodingSM->GetCurrentCharLen();
36
37 if (i == 0) {
38 mLastChar[1] = aBuf[0];
39 mDistributionAnalyser.HandleOneChar(mLastChar, charLen);
40 } else {
41 mDistributionAnalyser.HandleOneChar(aBuf + i - 1, charLen);
42 }
43 }
44 }
45
46 mLastChar[0] = aBuf[aLen - 1];
47
48 if (mState == eDetecting) {
49 if (mDistributionAnalyser.GotEnoughData() && GetConfidence() > SHORTCUT_THRESHOLD) {
50 mState = eFoundIt;
51 }
52 }
53
54 return mState;
55}
56
57float nsBig5Prober::GetConfidence(void)
58{
59 float distribCf = mDistributionAnalyser.GetConfidence();
60
61 return (float)distribCf;
62}
63}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.