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: #ifndef nsShiftJISToUnicode_h__ michael@0: #define nsShiftJISToUnicode_h__ michael@0: #include "nsUCSupport.h" michael@0: #include "mozilla/Telemetry.h" michael@0: michael@0: class nsShiftJISToUnicode : public nsBasicDecoderSupport michael@0: { michael@0: public: michael@0: michael@0: nsShiftJISToUnicode() michael@0: { michael@0: mState=0; mData=0; michael@0: } michael@0: virtual ~nsShiftJISToUnicode() {} michael@0: michael@0: NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength) ; michael@0: NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, michael@0: int32_t * aDestLength) michael@0: { michael@0: *aDestLength = aSrcLength; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHOD Reset() michael@0: { michael@0: mState = 0; michael@0: return NS_OK; michael@0: } michael@0: michael@0: virtual char16_t GetCharacterForUnMapped(); michael@0: michael@0: private: michael@0: michael@0: private: michael@0: int32_t mState; michael@0: int32_t mData; michael@0: }; michael@0: michael@0: class nsEUCJPToUnicodeV2 : public nsBasicDecoderSupport michael@0: { michael@0: public: michael@0: michael@0: nsEUCJPToUnicodeV2() michael@0: { michael@0: mState=0; mData=0; michael@0: } michael@0: virtual ~nsEUCJPToUnicodeV2() {} michael@0: michael@0: NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength) ; michael@0: NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, michael@0: int32_t * aDestLength) michael@0: { michael@0: *aDestLength = aSrcLength; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHOD Reset() michael@0: { michael@0: mState = 0; michael@0: return NS_OK; michael@0: } michael@0: michael@0: private: michael@0: int32_t mState; michael@0: int32_t mData; michael@0: }; michael@0: michael@0: class nsISO2022JPToUnicodeV2 : public nsBasicDecoderSupport michael@0: { michael@0: public: michael@0: michael@0: nsISO2022JPToUnicodeV2() michael@0: { michael@0: mState = mState_ASCII; michael@0: mLastLegalState = mState_ASCII; michael@0: mData = 0; michael@0: mRunLength = 0; michael@0: G2charset = G2_unknown; michael@0: mGB2312Decoder = nullptr; michael@0: mEUCKRDecoder = nullptr; michael@0: mISO88597Decoder = nullptr; michael@0: mozilla::Telemetry::Accumulate( michael@0: mozilla::Telemetry::DECODER_INSTANTIATED_ISO2022JP, true); michael@0: } michael@0: virtual ~nsISO2022JPToUnicodeV2() michael@0: { michael@0: NS_IF_RELEASE(mGB2312Decoder); michael@0: NS_IF_RELEASE(mEUCKRDecoder); michael@0: NS_IF_RELEASE(mISO88597Decoder); michael@0: } michael@0: michael@0: NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength) ; michael@0: NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, michael@0: int32_t * aDestLength) michael@0: { michael@0: *aDestLength = aSrcLength; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHOD Reset() michael@0: { michael@0: mState = mState_ASCII; michael@0: mLastLegalState = mState_ASCII; michael@0: mRunLength = 0; michael@0: return NS_OK; michael@0: } michael@0: michael@0: private: michael@0: enum { michael@0: mState_ASCII, michael@0: mState_ESC, michael@0: mState_ESC_28, michael@0: mState_ESC_24, michael@0: mState_ESC_24_28, michael@0: mState_JISX0201_1976Roman, michael@0: mState_JISX0201_1976Kana, michael@0: mState_JISX0208_1978, michael@0: mState_GB2312_1980, michael@0: mState_JISX0208_1983, michael@0: mState_KSC5601_1987, michael@0: mState_JISX0212_1990, michael@0: mState_JISX0208_1978_2ndbyte, michael@0: mState_GB2312_1980_2ndbyte, michael@0: mState_JISX0208_1983_2ndbyte, michael@0: mState_KSC5601_1987_2ndbyte, michael@0: mState_JISX0212_1990_2ndbyte, michael@0: mState_ESC_2e, michael@0: mState_ESC_4e, michael@0: mState_ERROR michael@0: } mState, mLastLegalState; michael@0: int32_t mData; michael@0: int32_t mRunLength; // the length of a non-ASCII run michael@0: enum { michael@0: G2_unknown, michael@0: G2_ISO88591, michael@0: G2_ISO88597 michael@0: } G2charset; michael@0: nsIUnicodeDecoder *mGB2312Decoder; michael@0: nsIUnicodeDecoder *mEUCKRDecoder; michael@0: nsIUnicodeDecoder *mISO88597Decoder; michael@0: }; michael@0: #endif // nsShiftJISToUnicode_h__