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 | void SetOpion() override |
34 | { |
35 | } |
36 | |
37 | protected: |
38 | nsInputState mInputState; |
39 | bool mDone; |
40 | bool mInTag; |
41 | bool mStart; |
42 | bool mGotData; |
43 | char mLastChar; |
44 | const char *mDetectedCharset; |
45 | int mBestGuess; |
46 | |
47 | nsCharSetProber *mCharSetProbers[NUM_OF_CHARSET_PROBERS]; |
48 | nsCharSetProber *mEscCharSetProber; |
49 | }; |
50 | } |
51 | |
52 | #endif |
53 | |