| 1 | /* -*- C++ -*- |
| 2 | SPDX-FileCopyrightText: 1998 Netscape Communications Corporation <developer@mozilla.org> |
| 3 | SPDX-FileCopyrightText: 2008 Wang Kai <zealot.kai@gmail.com> |
| 4 | |
| 5 | SPDX-License-Identifier: MIT |
| 6 | */ |
| 7 | |
| 8 | #ifndef nsUniversalDetector_h__ |
| 9 | #define nsUniversalDetector_h__ |
| 10 | |
| 11 | #include "nsCharSetProber.h" |
| 12 | |
| 13 | #define NUM_OF_CHARSET_PROBERS 3 |
| 14 | |
| 15 | namespace kencodingprober |
| 16 | { |
| 17 | typedef enum { |
| 18 | ePureAscii = 0, |
| 19 | eEscAscii = 1, |
| 20 | eHighbyte = 2, |
| 21 | } nsInputState; |
| 22 | |
| 23 | class KCODECS_NO_EXPORT nsUniversalDetector : public nsCharSetProber |
| 24 | { |
| 25 | public: |
| 26 | nsUniversalDetector(); |
| 27 | ~nsUniversalDetector() override; |
| 28 | nsProbingState HandleData(const char *aBuf, unsigned int aLen) override; |
| 29 | const char *GetCharSetName() override; |
| 30 | void Reset(void) override; |
| 31 | float GetConfidence(void) override; |
| 32 | nsProbingState GetState() override; |
| 33 | |
| 34 | protected: |
| 35 | nsInputState mInputState; |
| 36 | bool mDone; |
| 37 | bool mGotData; |
| 38 | char mLastChar; |
| 39 | const char *mDetectedCharset; |
| 40 | int mBestGuess; |
| 41 | |
| 42 | nsCharSetProber *mCharSetProbers[NUM_OF_CHARSET_PROBERS]; |
| 43 | nsCharSetProber *mEscCharSetProber; |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | #endif |
| 48 | |