Line data Source code
1 : /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 : #ifndef nsCharSetProber_h__
6 : #define nsCharSetProber_h__
7 :
8 : #include "nscore.h"
9 :
10 : //#define DEBUG_chardet // Uncomment this for debug dump.
11 :
12 : typedef enum {
13 : eDetecting = 0, //We are still detecting, no sure answer yet, but caller can ask for confidence.
14 : eFoundIt = 1, //That's a positive answer
15 : eNotMe = 2 //Negative answer
16 : } nsProbingState;
17 :
18 : #define SHORTCUT_THRESHOLD (float)0.95
19 :
20 0 : class nsCharSetProber {
21 : public:
22 0 : virtual ~nsCharSetProber() {}
23 : virtual const char* GetCharSetName() = 0;
24 : virtual nsProbingState HandleData(const char* aBuf, uint32_t aLen) = 0;
25 : virtual nsProbingState GetState(void) = 0;
26 : virtual void Reset(void) = 0;
27 : virtual float GetConfidence(void) = 0;
28 :
29 : #ifdef DEBUG_chardet
30 : virtual void DumpStatus() {};
31 : #endif
32 :
33 : // Helper functions used in the Latin1 and Group probers.
34 : // both functions Allocate a new buffer for newBuf. This buffer should be
35 : // freed by the caller using free().
36 : // Both functions return false in case of memory allocation failure.
37 : static bool FilterWithoutEnglishLetters(const char* aBuf, uint32_t aLen, char** newBuf, uint32_t& newLen);
38 : static bool FilterWithEnglishLetters(const char* aBuf, uint32_t aLen, char** newBuf, uint32_t& newLen);
39 :
40 : };
41 :
42 : #endif /* nsCharSetProber_h__ */
|