1 : /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Ervin Yan <Ervin.Yan@Sun.Com>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 : #ifndef nsISO2022CNToUnicode_h__
39 : #define nsISO2022CNToUnicode_h__
40 : #include "nsCOMPtr.h"
41 : #include "nsISupports.h"
42 : #include "nsUCSupport.h"
43 :
44 : #define MBYTE 0x8e
45 : #undef PMASK
46 : #define PMASK 0xa0
47 :
48 : #define SI 0x0f
49 : #define SO 0x0e
50 : #define ESC 0x1b
51 : #define SS2 0x4e
52 : #define SS3 0x4f
53 :
54 : class nsISO2022CNToUnicode : public nsBasicDecoderSupport
55 : {
56 : public:
57 0 : nsISO2022CNToUnicode() :
58 : mState(eState_ASCII),
59 : mPlaneID(0),
60 0 : mRunLength(0) { }
61 :
62 0 : virtual ~nsISO2022CNToUnicode() {}
63 :
64 : NS_IMETHOD Convert(const char *aSrc, PRInt32 * aSrcLength,
65 : PRUnichar * aDest, PRInt32 * aDestLength) ;
66 :
67 0 : NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
68 : PRInt32 * aDestLength)
69 : {
70 0 : *aDestLength = aSrcLength;
71 0 : return NS_OK;
72 : }
73 :
74 0 : NS_IMETHOD Reset()
75 : {
76 0 : mState = eState_ASCII;
77 0 : mPlaneID = 0;
78 0 : mRunLength = 0;
79 :
80 0 : return NS_OK;
81 : }
82 :
83 : private:
84 : // State Machine ID
85 : enum {
86 : eState_ASCII,
87 : eState_ESC, // ESC
88 : eState_ESC_24, // ESC $
89 :
90 : eState_ESC_24_29, // ESC $ )
91 : eState_ESC_24_29_A, // ESC $ ) A
92 : eState_GB2312_1980, // ESC $ ) A SO
93 : eState_GB2312_1980_2ndbyte, // ESC $ ) A SO
94 : eState_ESC_24_29_A_SO_SI, // ESC $ ) A SO SI
95 : eState_ESC_24_29_G, // ESC $ ) G or H
96 : eState_CNS11643_1, // ESC $ ) G SO
97 : eState_CNS11643_1_2ndbyte, // ESC $ ) G SO
98 : eState_ESC_24_29_G_SO_SI, // ESC $ ) G SO SI
99 :
100 : eState_ESC_24_2A, // ESC $ *
101 : eState_ESC_24_2A_H, // ESC $ * H
102 : eState_ESC_24_2A_H_ESC, // ESC $ * H ESC
103 : eState_CNS11643_2, // ESC $ * H ESC SS2
104 : eState_CNS11643_2_2ndbyte, // ESC $ * H ESC SS2
105 : eState_ESC_24_2A_H_ESC_SS2_SI, // ESC $ * H ESC SS2 SI
106 : eState_ESC_24_2A_H_ESC_SS2_SI_ESC, // ESC $ * H ESC SS2 SI ESC
107 :
108 : eState_ESC_24_2B, // ESC $ +
109 : eState_ESC_24_2B_I, // ESC $ + I
110 : eState_ESC_24_2B_I_ESC, // ESC $ + I ESC
111 : eState_CNS11643_3, // ESC $ + I ESC SS3
112 : eState_CNS11643_3_2ndbyte, // ESC $ + I ESC SS3
113 : eState_ESC_24_2B_I_ESC_SS3_SI, // ESC $ + I ESC SI
114 : eState_ESC_24_2B_I_ESC_SS3_SI_ESC, // ESC $ + I ESC SI ESC
115 : eState_ERROR
116 : } mState;
117 :
118 : char mData;
119 :
120 : // Plane number for CNS11643 code
121 : int mPlaneID;
122 :
123 : // Length of non-ASCII run
124 : PRUint32 mRunLength;
125 :
126 : // Decoder handler
127 : nsCOMPtr<nsIUnicodeDecoder> mGB2312_Decoder;
128 : nsCOMPtr<nsIUnicodeDecoder> mEUCTW_Decoder;
129 :
130 : NS_IMETHOD GB2312_To_Unicode(unsigned char *aSrc, PRInt32 aSrcLength,
131 : PRUnichar * aDest, PRInt32 * aDestLength) ;
132 :
133 : NS_IMETHOD EUCTW_To_Unicode(unsigned char *aSrc, PRInt32 aSrcLength,
134 : PRUnichar * aDest, PRInt32 * aDestLength) ;
135 : };
136 : #endif // nsISO2022CNToUnicode_h__
|