File indexing completed on 2024-05-05 16:05:51
0001 /* -*- C++ -*- 0002 SPDX-FileCopyrightText: 1998 Netscape Communications Corporation <developer@mozilla.org> 0003 SPDX-FileCopyrightText: 2008 Wang Kai <zealot.kai@gmail.com> 0004 0005 SPDX-License-Identifier: MIT 0006 */ 0007 0008 #ifndef nsUniversalDetector_h__ 0009 #define nsUniversalDetector_h__ 0010 0011 #include "nsCharSetProber.h" 0012 0013 #define NUM_OF_CHARSET_PROBERS 3 0014 0015 namespace kencodingprober 0016 { 0017 typedef enum { 0018 ePureAscii = 0, 0019 eEscAscii = 1, 0020 eHighbyte = 2, 0021 } nsInputState; 0022 0023 class KCODECS_NO_EXPORT nsUniversalDetector : public nsCharSetProber 0024 { 0025 public: 0026 nsUniversalDetector(); 0027 ~nsUniversalDetector() override; 0028 nsProbingState HandleData(const char *aBuf, unsigned int aLen) override; 0029 const char *GetCharSetName() override; 0030 void Reset(void) override; 0031 float GetConfidence(void) override; 0032 nsProbingState GetState() override; 0033 void SetOpion() override 0034 { 0035 } 0036 0037 protected: 0038 nsInputState mInputState; 0039 bool mDone; 0040 bool mInTag; 0041 bool mStart; 0042 bool mGotData; 0043 char mLastChar; 0044 const char *mDetectedCharset; 0045 int mBestGuess; 0046 0047 nsCharSetProber *mCharSetProbers[NUM_OF_CHARSET_PROBERS]; 0048 nsCharSetProber *mEscCharSetProber; 0049 }; 0050 } 0051 0052 #endif