1 | /* -*- C++ -*- |
2 | SPDX-FileCopyrightText: 1998 Netscape Communications Corporation <developer@mozilla.org> |
3 | |
4 | SPDX-License-Identifier: MIT |
5 | */ |
6 | |
7 | #ifndef nsCharSetProber_h__ |
8 | #define nsCharSetProber_h__ |
9 | |
10 | #include "kencodingprober.h" |
11 | |
12 | namespace kencodingprober |
13 | { |
14 | typedef enum { |
15 | eDetecting = 0, // We are still detecting, no sure answer yet, but caller can ask for confidence. |
16 | eFoundIt = 1, // That's a positive answer |
17 | eNotMe = 2, // Negative answer |
18 | } nsProbingState; |
19 | |
20 | #define SHORTCUT_THRESHOLD (float)0.95 |
21 | |
22 | class KCODECS_NO_EXPORT nsCharSetProber |
23 | { |
24 | public: |
25 | virtual ~nsCharSetProber() |
26 | { |
27 | } |
28 | virtual const char *GetCharSetName() = 0; |
29 | virtual nsProbingState HandleData(const char *aBuf, unsigned int aLen) = 0; |
30 | virtual nsProbingState GetState(void) = 0; |
31 | virtual void Reset(void) = 0; |
32 | virtual float GetConfidence(void) = 0; |
33 | virtual void SetOpion() = 0; |
34 | |
35 | #ifdef DEBUG_PROBE |
36 | void DumpStatus() override |
37 | { |
38 | } |
39 | #endif |
40 | |
41 | // Helper functions used in the Latin1 and Group probers. |
42 | // both functions Allocate a new buffer for newBuf. This buffer should be |
43 | // freed by the caller using PR_FREEIF. |
44 | // Both functions return false in case of memory allocation failure. |
45 | static bool FilterWithoutEnglishLetters(const char *aBuf, unsigned int aLen, char **newBuf, unsigned int &newLen); |
46 | static bool FilterWithEnglishLetters(const char *aBuf, unsigned int aLen, char **newBuf, unsigned int &newLen); |
47 | }; |
48 | } |
49 | #endif /* nsCharSetProber_h__ */ |
50 | |