Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; 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 nsShiftJISToUnicode_h__ |
michael@0 | 6 | #define nsShiftJISToUnicode_h__ |
michael@0 | 7 | #include "nsUCSupport.h" |
michael@0 | 8 | #include "mozilla/Telemetry.h" |
michael@0 | 9 | |
michael@0 | 10 | class nsShiftJISToUnicode : public nsBasicDecoderSupport |
michael@0 | 11 | { |
michael@0 | 12 | public: |
michael@0 | 13 | |
michael@0 | 14 | nsShiftJISToUnicode() |
michael@0 | 15 | { |
michael@0 | 16 | mState=0; mData=0; |
michael@0 | 17 | } |
michael@0 | 18 | virtual ~nsShiftJISToUnicode() {} |
michael@0 | 19 | |
michael@0 | 20 | NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, |
michael@0 | 21 | char16_t * aDest, int32_t * aDestLength) ; |
michael@0 | 22 | NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, |
michael@0 | 23 | int32_t * aDestLength) |
michael@0 | 24 | { |
michael@0 | 25 | *aDestLength = aSrcLength; |
michael@0 | 26 | return NS_OK; |
michael@0 | 27 | } |
michael@0 | 28 | NS_IMETHOD Reset() |
michael@0 | 29 | { |
michael@0 | 30 | mState = 0; |
michael@0 | 31 | return NS_OK; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | virtual char16_t GetCharacterForUnMapped(); |
michael@0 | 35 | |
michael@0 | 36 | private: |
michael@0 | 37 | |
michael@0 | 38 | private: |
michael@0 | 39 | int32_t mState; |
michael@0 | 40 | int32_t mData; |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | class nsEUCJPToUnicodeV2 : public nsBasicDecoderSupport |
michael@0 | 44 | { |
michael@0 | 45 | public: |
michael@0 | 46 | |
michael@0 | 47 | nsEUCJPToUnicodeV2() |
michael@0 | 48 | { |
michael@0 | 49 | mState=0; mData=0; |
michael@0 | 50 | } |
michael@0 | 51 | virtual ~nsEUCJPToUnicodeV2() {} |
michael@0 | 52 | |
michael@0 | 53 | NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, |
michael@0 | 54 | char16_t * aDest, int32_t * aDestLength) ; |
michael@0 | 55 | NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, |
michael@0 | 56 | int32_t * aDestLength) |
michael@0 | 57 | { |
michael@0 | 58 | *aDestLength = aSrcLength; |
michael@0 | 59 | return NS_OK; |
michael@0 | 60 | } |
michael@0 | 61 | NS_IMETHOD Reset() |
michael@0 | 62 | { |
michael@0 | 63 | mState = 0; |
michael@0 | 64 | return NS_OK; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | private: |
michael@0 | 68 | int32_t mState; |
michael@0 | 69 | int32_t mData; |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | class nsISO2022JPToUnicodeV2 : public nsBasicDecoderSupport |
michael@0 | 73 | { |
michael@0 | 74 | public: |
michael@0 | 75 | |
michael@0 | 76 | nsISO2022JPToUnicodeV2() |
michael@0 | 77 | { |
michael@0 | 78 | mState = mState_ASCII; |
michael@0 | 79 | mLastLegalState = mState_ASCII; |
michael@0 | 80 | mData = 0; |
michael@0 | 81 | mRunLength = 0; |
michael@0 | 82 | G2charset = G2_unknown; |
michael@0 | 83 | mGB2312Decoder = nullptr; |
michael@0 | 84 | mEUCKRDecoder = nullptr; |
michael@0 | 85 | mISO88597Decoder = nullptr; |
michael@0 | 86 | mozilla::Telemetry::Accumulate( |
michael@0 | 87 | mozilla::Telemetry::DECODER_INSTANTIATED_ISO2022JP, true); |
michael@0 | 88 | } |
michael@0 | 89 | virtual ~nsISO2022JPToUnicodeV2() |
michael@0 | 90 | { |
michael@0 | 91 | NS_IF_RELEASE(mGB2312Decoder); |
michael@0 | 92 | NS_IF_RELEASE(mEUCKRDecoder); |
michael@0 | 93 | NS_IF_RELEASE(mISO88597Decoder); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, |
michael@0 | 97 | char16_t * aDest, int32_t * aDestLength) ; |
michael@0 | 98 | NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, |
michael@0 | 99 | int32_t * aDestLength) |
michael@0 | 100 | { |
michael@0 | 101 | *aDestLength = aSrcLength; |
michael@0 | 102 | return NS_OK; |
michael@0 | 103 | } |
michael@0 | 104 | NS_IMETHOD Reset() |
michael@0 | 105 | { |
michael@0 | 106 | mState = mState_ASCII; |
michael@0 | 107 | mLastLegalState = mState_ASCII; |
michael@0 | 108 | mRunLength = 0; |
michael@0 | 109 | return NS_OK; |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | private: |
michael@0 | 113 | enum { |
michael@0 | 114 | mState_ASCII, |
michael@0 | 115 | mState_ESC, |
michael@0 | 116 | mState_ESC_28, |
michael@0 | 117 | mState_ESC_24, |
michael@0 | 118 | mState_ESC_24_28, |
michael@0 | 119 | mState_JISX0201_1976Roman, |
michael@0 | 120 | mState_JISX0201_1976Kana, |
michael@0 | 121 | mState_JISX0208_1978, |
michael@0 | 122 | mState_GB2312_1980, |
michael@0 | 123 | mState_JISX0208_1983, |
michael@0 | 124 | mState_KSC5601_1987, |
michael@0 | 125 | mState_JISX0212_1990, |
michael@0 | 126 | mState_JISX0208_1978_2ndbyte, |
michael@0 | 127 | mState_GB2312_1980_2ndbyte, |
michael@0 | 128 | mState_JISX0208_1983_2ndbyte, |
michael@0 | 129 | mState_KSC5601_1987_2ndbyte, |
michael@0 | 130 | mState_JISX0212_1990_2ndbyte, |
michael@0 | 131 | mState_ESC_2e, |
michael@0 | 132 | mState_ESC_4e, |
michael@0 | 133 | mState_ERROR |
michael@0 | 134 | } mState, mLastLegalState; |
michael@0 | 135 | int32_t mData; |
michael@0 | 136 | int32_t mRunLength; // the length of a non-ASCII run |
michael@0 | 137 | enum { |
michael@0 | 138 | G2_unknown, |
michael@0 | 139 | G2_ISO88591, |
michael@0 | 140 | G2_ISO88597 |
michael@0 | 141 | } G2charset; |
michael@0 | 142 | nsIUnicodeDecoder *mGB2312Decoder; |
michael@0 | 143 | nsIUnicodeDecoder *mEUCKRDecoder; |
michael@0 | 144 | nsIUnicodeDecoder *mISO88597Decoder; |
michael@0 | 145 | }; |
michael@0 | 146 | #endif // nsShiftJISToUnicode_h__ |