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 nsISO2022CNToUnicode_h__ michael@0: #define nsISO2022CNToUnicode_h__ michael@0: #include "nsCOMPtr.h" michael@0: #include "nsUCSupport.h" michael@0: #include "mozilla/Telemetry.h" michael@0: michael@0: #define MBYTE 0x8e michael@0: #undef PMASK michael@0: #define PMASK 0xa0 michael@0: michael@0: #define SI 0x0f michael@0: #define SO 0x0e michael@0: #define ESC 0x1b michael@0: #define SS2 0x4e michael@0: #define SS3 0x4f michael@0: michael@0: class nsISO2022CNToUnicode : public nsBasicDecoderSupport michael@0: { michael@0: public: michael@0: nsISO2022CNToUnicode() : michael@0: mState(eState_ASCII), michael@0: mPlaneID(0), michael@0: mRunLength(0) michael@0: { michael@0: mozilla::Telemetry::Accumulate( michael@0: mozilla::Telemetry::DECODER_INSTANTIATED_ISO2022CN, true); michael@0: } michael@0: michael@0: virtual ~nsISO2022CNToUnicode() {} michael@0: michael@0: NS_IMETHOD Convert(const char *aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength) ; michael@0: 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: michael@0: NS_IMETHOD Reset() michael@0: { michael@0: mState = eState_ASCII; michael@0: mPlaneID = 0; michael@0: mRunLength = 0; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: private: michael@0: // State Machine ID michael@0: enum { michael@0: eState_ASCII, michael@0: eState_ESC, // ESC michael@0: eState_ESC_24, // ESC $ michael@0: michael@0: eState_ESC_24_29, // ESC $ ) michael@0: eState_ESC_24_29_A, // ESC $ ) A michael@0: eState_GB2312_1980, // ESC $ ) A SO michael@0: eState_GB2312_1980_2ndbyte, // ESC $ ) A SO michael@0: eState_ESC_24_29_A_SO_SI, // ESC $ ) A SO SI michael@0: eState_ESC_24_29_G, // ESC $ ) G or H michael@0: eState_CNS11643_1, // ESC $ ) G SO michael@0: eState_CNS11643_1_2ndbyte, // ESC $ ) G SO michael@0: eState_ESC_24_29_G_SO_SI, // ESC $ ) G SO SI michael@0: michael@0: eState_ESC_24_2A, // ESC $ * michael@0: eState_ESC_24_2A_H, // ESC $ * H michael@0: eState_ESC_24_2A_H_ESC, // ESC $ * H ESC michael@0: eState_CNS11643_2, // ESC $ * H ESC SS2 michael@0: eState_CNS11643_2_2ndbyte, // ESC $ * H ESC SS2 michael@0: eState_ESC_24_2A_H_ESC_SS2_SI, // ESC $ * H ESC SS2 SI michael@0: eState_ESC_24_2A_H_ESC_SS2_SI_ESC, // ESC $ * H ESC SS2 SI ESC michael@0: michael@0: eState_ESC_24_2B, // ESC $ + michael@0: eState_ESC_24_2B_I, // ESC $ + I michael@0: eState_ESC_24_2B_I_ESC, // ESC $ + I ESC michael@0: eState_CNS11643_3, // ESC $ + I ESC SS3 michael@0: eState_CNS11643_3_2ndbyte, // ESC $ + I ESC SS3 michael@0: eState_ESC_24_2B_I_ESC_SS3_SI, // ESC $ + I ESC SI michael@0: eState_ESC_24_2B_I_ESC_SS3_SI_ESC, // ESC $ + I ESC SI ESC michael@0: eState_ERROR michael@0: } mState; michael@0: michael@0: char mData; michael@0: michael@0: // Plane number for CNS11643 code michael@0: int mPlaneID; michael@0: michael@0: // Length of non-ASCII run michael@0: uint32_t mRunLength; michael@0: michael@0: // Decoder handler michael@0: nsCOMPtr mGB2312_Decoder; michael@0: nsCOMPtr mEUCTW_Decoder; michael@0: michael@0: NS_IMETHOD GB2312_To_Unicode(unsigned char *aSrc, int32_t aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength) ; michael@0: michael@0: NS_IMETHOD EUCTW_To_Unicode(unsigned char *aSrc, int32_t aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength) ; michael@0: }; michael@0: #endif // nsISO2022CNToUnicode_h__