michael@0: /* -*- Mode: C++; tab-width: 2; 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: michael@0: #ifndef nsUniversalDetector_h__ michael@0: #define nsUniversalDetector_h__ michael@0: michael@0: class nsCharSetProber; michael@0: michael@0: #define NUM_OF_CHARSET_PROBERS 3 michael@0: michael@0: typedef enum { michael@0: ePureAscii = 0, michael@0: eEscAscii = 1, michael@0: eHighbyte = 2 michael@0: } nsInputState; michael@0: michael@0: #define NS_FILTER_CHINESE_SIMPLIFIED 0x01 michael@0: #define NS_FILTER_CHINESE_TRADITIONAL 0x02 michael@0: #define NS_FILTER_JAPANESE 0x04 michael@0: #define NS_FILTER_KOREAN 0x08 michael@0: #define NS_FILTER_NON_CJK 0x10 michael@0: #define NS_FILTER_ALL 0x1F michael@0: #define NS_FILTER_CHINESE (NS_FILTER_CHINESE_SIMPLIFIED | \ michael@0: NS_FILTER_CHINESE_TRADITIONAL) michael@0: #define NS_FILTER_CJK (NS_FILTER_CHINESE_SIMPLIFIED | \ michael@0: NS_FILTER_CHINESE_TRADITIONAL | \ michael@0: NS_FILTER_JAPANESE | \ michael@0: NS_FILTER_KOREAN) michael@0: michael@0: class nsUniversalDetector { michael@0: public: michael@0: nsUniversalDetector(uint32_t aLanguageFilter); michael@0: virtual ~nsUniversalDetector(); michael@0: virtual nsresult HandleData(const char* aBuf, uint32_t aLen); michael@0: virtual void DataEnd(void); michael@0: michael@0: protected: michael@0: virtual void Report(const char* aCharset) = 0; michael@0: virtual void Reset(); michael@0: nsInputState mInputState; michael@0: bool mDone; michael@0: bool mInTag; michael@0: bool mStart; michael@0: bool mGotData; michael@0: char mLastChar; michael@0: const char * mDetectedCharset; michael@0: int32_t mBestGuess; michael@0: uint32_t mLanguageFilter; michael@0: michael@0: nsCharSetProber *mCharSetProbers[NUM_OF_CHARSET_PROBERS]; michael@0: nsCharSetProber *mEscCharSetProber; michael@0: }; michael@0: michael@0: #endif michael@0: