michael@0: /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsCharSetProber_h__ michael@0: #define nsCharSetProber_h__ michael@0: michael@0: #include "nscore.h" michael@0: michael@0: //#define DEBUG_chardet // Uncomment this for debug dump. michael@0: michael@0: typedef enum { michael@0: eDetecting = 0, //We are still detecting, no sure answer yet, but caller can ask for confidence. michael@0: eFoundIt = 1, //That's a positive answer michael@0: eNotMe = 2 //Negative answer michael@0: } nsProbingState; michael@0: michael@0: #define SHORTCUT_THRESHOLD (float)0.95 michael@0: michael@0: class nsCharSetProber { michael@0: public: michael@0: virtual ~nsCharSetProber() {} michael@0: virtual const char* GetCharSetName() = 0; michael@0: virtual nsProbingState HandleData(const char* aBuf, uint32_t aLen) = 0; michael@0: virtual nsProbingState GetState(void) = 0; michael@0: virtual void Reset(void) = 0; michael@0: virtual float GetConfidence(void) = 0; michael@0: michael@0: #ifdef DEBUG_chardet michael@0: virtual void DumpStatus() {}; michael@0: #endif michael@0: michael@0: // Helper functions used in the Latin1 and Group probers. michael@0: // both functions Allocate a new buffer for newBuf. This buffer should be michael@0: // freed by the caller using PR_FREEIF. michael@0: // Both functions return false in case of memory allocation failure. michael@0: static bool FilterWithoutEnglishLetters(const char* aBuf, uint32_t aLen, char** newBuf, uint32_t& newLen); michael@0: static bool FilterWithEnglishLetters(const char* aBuf, uint32_t aLen, char** newBuf, uint32_t& newLen); michael@0: michael@0: }; michael@0: michael@0: #endif /* nsCharSetProber_h__ */