File indexing completed on 2024-04-28 03:53:04

0001 /*
0002     The Original Code is mozilla.org code.
0003 
0004     SPDX-FileCopyrightText: 1998 Netscape Communications Corporation
0005 
0006     SPDX-License-Identifier: MPL-1.1 OR GPL-2.0-or-later OR LGPL-2.1-or-later
0007 */
0008 
0009 // for S-JIS encoding, observe characteristic:
0010 // 1, kana character (or hankaku?) often have high frequency of appearance
0011 // 2, kana character often exist in group
0012 // 3, certain combination of kana is never used in japanese language
0013 
0014 #ifndef nsSJISProber_h__
0015 #define nsSJISProber_h__
0016 
0017 #include "CharDistribution.h"
0018 #include "JpCntx.h"
0019 #include "nsCharSetProber.h"
0020 #include "nsCodingStateMachine.h"
0021 
0022 namespace kencodingprober
0023 {
0024 class KCODECS_NO_EXPORT nsSJISProber : public nsCharSetProber
0025 {
0026 public:
0027     nsSJISProber(void)
0028     {
0029         mCodingSM = new nsCodingStateMachine(&SJISSMModel);
0030         Reset();
0031     }
0032     ~nsSJISProber(void) override
0033     {
0034         delete mCodingSM;
0035     }
0036     nsProbingState HandleData(const char *aBuf, unsigned int aLen) override;
0037     const char *GetCharSetName() override
0038     {
0039         return "Shift_JIS";
0040     }
0041     nsProbingState GetState(void) override
0042     {
0043         return mState;
0044     }
0045     void Reset(void) override;
0046     float GetConfidence(void) override;
0047     void SetOpion() override
0048     {
0049     }
0050 
0051 protected:
0052     nsCodingStateMachine *mCodingSM;
0053     nsProbingState mState;
0054 
0055     SJISContextAnalysis mContextAnalyser;
0056     SJISDistributionAnalysis mDistributionAnalyser;
0057 
0058     char mLastChar[2];
0059 };
0060 }
0061 
0062 #endif /* nsSJISProber_h__ */