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