| 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 | |
| 34 | #ifdef DEBUG_PROBE |
| 35 | void DumpStatus() override |
| 36 | { |
| 37 | } |
| 38 | #endif |
| 39 | |
| 40 | // Helper functions used in the Latin1 and Group probers. |
| 41 | // both functions Allocate a new buffer for newBuf. This buffer should be |
| 42 | // freed by the caller using PR_FREEIF. |
| 43 | // Both functions return false in case of memory allocation failure. |
| 44 | static bool FilterWithoutEnglishLetters(const char *aBuf, unsigned int aLen, char **newBuf, unsigned int &newLen); |
| 45 | static bool FilterWithEnglishLetters(const char *aBuf, unsigned int aLen, char **newBuf, unsigned int &newLen); |
| 46 | }; |
| 47 | } |
| 48 | #endif /* nsCharSetProber_h__ */ |
| 49 | |