| 1 | /* |
| 2 | The Original Code is mozilla.org code. |
| 3 | |
| 4 | SPDX-FileCopyrightText: 1998 Netscape Communications Corporation |
| 5 | |
| 6 | SPDX-License-Identifier: MPL-1.1 OR GPL-2.0-or-later OR LGPL-2.1-or-later |
| 7 | */ |
| 8 | |
| 9 | // for S-JIS encoding, observe characteristic: |
| 10 | // 1, kana character (or hankaku?) often have high frequency of appearance |
| 11 | // 2, kana character often exist in group |
| 12 | // 3, certain combination of kana is never used in japanese language |
| 13 | |
| 14 | #ifndef nsSJISProber_h__ |
| 15 | #define nsSJISProber_h__ |
| 16 | |
| 17 | #include "CharDistribution.h" |
| 18 | #include "JpCntx.h" |
| 19 | #include "nsCharSetProber.h" |
| 20 | #include "nsCodingStateMachine.h" |
| 21 | |
| 22 | namespace kencodingprober |
| 23 | { |
| 24 | class KCODECS_NO_EXPORT nsSJISProber : public nsCharSetProber |
| 25 | { |
| 26 | public: |
| 27 | nsSJISProber(void) |
| 28 | { |
| 29 | mCodingSM = new nsCodingStateMachine(&SJISSMModel); |
| 30 | Reset(); |
| 31 | } |
| 32 | ~nsSJISProber(void) override |
| 33 | { |
| 34 | delete mCodingSM; |
| 35 | } |
| 36 | nsProbingState HandleData(const char *aBuf, unsigned int aLen) override; |
| 37 | const char *GetCharSetName() override |
| 38 | { |
| 39 | return "Shift_JIS" ; |
| 40 | } |
| 41 | nsProbingState GetState(void) override |
| 42 | { |
| 43 | return mState; |
| 44 | } |
| 45 | void Reset(void) override; |
| 46 | float GetConfidence(void) override; |
| 47 | |
| 48 | protected: |
| 49 | nsCodingStateMachine *mCodingSM; |
| 50 | nsProbingState mState; |
| 51 | |
| 52 | SJISContextAnalysis mContextAnalyser; |
| 53 | SJISDistributionAnalysis mDistributionAnalyser; |
| 54 | |
| 55 | char mLastChar[2]; |
| 56 | }; |
| 57 | } |
| 58 | |
| 59 | #endif /* nsSJISProber_h__ */ |
| 60 | |