KCodecs

nsEUCKRProber.cpp
1/* -*- C++ -*-
2 SPDX-FileCopyrightText: 1998 Netscape Communications Corporation <developer@mozilla.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include "nsEUCKRProber.h"
8
9namespace kencodingprober
10{
11void nsEUCKRProber::Reset(void)
12{
13 mCodingSM->Reset();
14 mState = eDetecting;
15 mDistributionAnalyser.Reset();
16 // mContextAnalyser.Reset();
17}
18
19nsProbingState nsEUCKRProber::HandleData(const char *aBuf, unsigned int aLen)
20{
21 if (aLen == 0) {
22 return mState;
23 }
24
25 for (unsigned int i = 0; i < aLen; i++) {
26 const nsSMState codingState = mCodingSM->NextState(aBuf[i]);
27 if (codingState == eError) {
28 mState = eNotMe;
29 break;
30 }
31 if (codingState == eItsMe) {
32 mState = eFoundIt;
33 break;
34 }
35 if (codingState == eStart) {
36 unsigned int charLen = mCodingSM->GetCurrentCharLen();
37
38 if (i == 0) {
39 mLastChar[1] = aBuf[0];
40 mDistributionAnalyser.HandleOneChar(mLastChar, charLen);
41 } else {
42 mDistributionAnalyser.HandleOneChar(aBuf + i - 1, charLen);
43 }
44 }
45 }
46
47 mLastChar[0] = aBuf[aLen - 1];
48
49 if (mState == eDetecting) {
50 if (mDistributionAnalyser.GotEnoughData() && GetConfidence() > SHORTCUT_THRESHOLD) {
51 mState = eFoundIt;
52 }
53 }
54 // else
55 // mDistributionAnalyser.HandleData(aBuf, aLen);
56
57 return mState;
58}
59
60float nsEUCKRProber::GetConfidence(void)
61{
62 float distribCf = mDistributionAnalyser.GetConfidence();
63
64 return (float)distribCf;
65}
66}
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.