|
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 #ifndef nsISO2022CNToUnicode_h__ |
|
6 #define nsISO2022CNToUnicode_h__ |
|
7 #include "nsCOMPtr.h" |
|
8 #include "nsUCSupport.h" |
|
9 #include "mozilla/Telemetry.h" |
|
10 |
|
11 #define MBYTE 0x8e |
|
12 #undef PMASK |
|
13 #define PMASK 0xa0 |
|
14 |
|
15 #define SI 0x0f |
|
16 #define SO 0x0e |
|
17 #define ESC 0x1b |
|
18 #define SS2 0x4e |
|
19 #define SS3 0x4f |
|
20 |
|
21 class nsISO2022CNToUnicode : public nsBasicDecoderSupport |
|
22 { |
|
23 public: |
|
24 nsISO2022CNToUnicode() : |
|
25 mState(eState_ASCII), |
|
26 mPlaneID(0), |
|
27 mRunLength(0) |
|
28 { |
|
29 mozilla::Telemetry::Accumulate( |
|
30 mozilla::Telemetry::DECODER_INSTANTIATED_ISO2022CN, true); |
|
31 } |
|
32 |
|
33 virtual ~nsISO2022CNToUnicode() {} |
|
34 |
|
35 NS_IMETHOD Convert(const char *aSrc, int32_t * aSrcLength, |
|
36 char16_t * aDest, int32_t * aDestLength) ; |
|
37 |
|
38 NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, |
|
39 int32_t * aDestLength) |
|
40 { |
|
41 *aDestLength = aSrcLength; |
|
42 return NS_OK; |
|
43 } |
|
44 |
|
45 NS_IMETHOD Reset() |
|
46 { |
|
47 mState = eState_ASCII; |
|
48 mPlaneID = 0; |
|
49 mRunLength = 0; |
|
50 |
|
51 return NS_OK; |
|
52 } |
|
53 |
|
54 private: |
|
55 // State Machine ID |
|
56 enum { |
|
57 eState_ASCII, |
|
58 eState_ESC, // ESC |
|
59 eState_ESC_24, // ESC $ |
|
60 |
|
61 eState_ESC_24_29, // ESC $ ) |
|
62 eState_ESC_24_29_A, // ESC $ ) A |
|
63 eState_GB2312_1980, // ESC $ ) A SO |
|
64 eState_GB2312_1980_2ndbyte, // ESC $ ) A SO |
|
65 eState_ESC_24_29_A_SO_SI, // ESC $ ) A SO SI |
|
66 eState_ESC_24_29_G, // ESC $ ) G or H |
|
67 eState_CNS11643_1, // ESC $ ) G SO |
|
68 eState_CNS11643_1_2ndbyte, // ESC $ ) G SO |
|
69 eState_ESC_24_29_G_SO_SI, // ESC $ ) G SO SI |
|
70 |
|
71 eState_ESC_24_2A, // ESC $ * |
|
72 eState_ESC_24_2A_H, // ESC $ * H |
|
73 eState_ESC_24_2A_H_ESC, // ESC $ * H ESC |
|
74 eState_CNS11643_2, // ESC $ * H ESC SS2 |
|
75 eState_CNS11643_2_2ndbyte, // ESC $ * H ESC SS2 |
|
76 eState_ESC_24_2A_H_ESC_SS2_SI, // ESC $ * H ESC SS2 SI |
|
77 eState_ESC_24_2A_H_ESC_SS2_SI_ESC, // ESC $ * H ESC SS2 SI ESC |
|
78 |
|
79 eState_ESC_24_2B, // ESC $ + |
|
80 eState_ESC_24_2B_I, // ESC $ + I |
|
81 eState_ESC_24_2B_I_ESC, // ESC $ + I ESC |
|
82 eState_CNS11643_3, // ESC $ + I ESC SS3 |
|
83 eState_CNS11643_3_2ndbyte, // ESC $ + I ESC SS3 |
|
84 eState_ESC_24_2B_I_ESC_SS3_SI, // ESC $ + I ESC SI |
|
85 eState_ESC_24_2B_I_ESC_SS3_SI_ESC, // ESC $ + I ESC SI ESC |
|
86 eState_ERROR |
|
87 } mState; |
|
88 |
|
89 char mData; |
|
90 |
|
91 // Plane number for CNS11643 code |
|
92 int mPlaneID; |
|
93 |
|
94 // Length of non-ASCII run |
|
95 uint32_t mRunLength; |
|
96 |
|
97 // Decoder handler |
|
98 nsCOMPtr<nsIUnicodeDecoder> mGB2312_Decoder; |
|
99 nsCOMPtr<nsIUnicodeDecoder> mEUCTW_Decoder; |
|
100 |
|
101 NS_IMETHOD GB2312_To_Unicode(unsigned char *aSrc, int32_t aSrcLength, |
|
102 char16_t * aDest, int32_t * aDestLength) ; |
|
103 |
|
104 NS_IMETHOD EUCTW_To_Unicode(unsigned char *aSrc, int32_t aSrcLength, |
|
105 char16_t * aDest, int32_t * aDestLength) ; |
|
106 }; |
|
107 #endif // nsISO2022CNToUnicode_h__ |