1 : /* -*- Mode: C++; tab-width: 2; 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 Communicator client 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 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 : #ifndef nsShiftJISToUnicode_h__
38 : #define nsShiftJISToUnicode_h__
39 : #include "nsISupports.h"
40 : #include "nsUCSupport.h"
41 :
42 :
43 : class nsShiftJISToUnicode : public nsBasicDecoderSupport
44 : {
45 : public:
46 :
47 5 : nsShiftJISToUnicode()
48 5 : {
49 5 : mState=0; mData=0;
50 5 : }
51 20 : virtual ~nsShiftJISToUnicode() {}
52 :
53 : NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
54 : PRUnichar * aDest, PRInt32 * aDestLength) ;
55 65154 : NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
56 : PRInt32 * aDestLength)
57 : {
58 65154 : *aDestLength = aSrcLength;
59 65154 : return NS_OK;
60 : }
61 0 : NS_IMETHOD Reset()
62 : {
63 0 : mState = 0;
64 0 : return NS_OK;
65 : }
66 :
67 : virtual PRUnichar GetCharacterForUnMapped();
68 :
69 : private:
70 :
71 : private:
72 : PRInt32 mState;
73 : PRInt32 mData;
74 : };
75 :
76 : class nsEUCJPToUnicodeV2 : public nsBasicDecoderSupport
77 : {
78 : public:
79 :
80 35 : nsEUCJPToUnicodeV2()
81 35 : {
82 35 : mState=0; mData=0;
83 35 : }
84 140 : virtual ~nsEUCJPToUnicodeV2() {}
85 :
86 : NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
87 : PRUnichar * aDest, PRInt32 * aDestLength) ;
88 129923 : NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
89 : PRInt32 * aDestLength)
90 : {
91 129923 : *aDestLength = aSrcLength;
92 129923 : return NS_OK;
93 : }
94 0 : NS_IMETHOD Reset()
95 : {
96 0 : mState = 0;
97 0 : return NS_OK;
98 : }
99 :
100 : private:
101 : PRInt32 mState;
102 : PRInt32 mData;
103 : };
104 :
105 : class nsISO2022JPToUnicodeV2 : public nsBasicDecoderSupport
106 : {
107 : public:
108 :
109 9 : nsISO2022JPToUnicodeV2()
110 9 : {
111 9 : mState = mState_ASCII;
112 9 : mLastLegalState = mState_ASCII;
113 9 : mData = 0;
114 9 : mRunLength = 0;
115 9 : G2charset = G2_unknown;
116 9 : mGB2312Decoder = nsnull;
117 9 : mEUCKRDecoder = nsnull;
118 9 : mISO88597Decoder = nsnull;
119 9 : }
120 18 : virtual ~nsISO2022JPToUnicodeV2()
121 18 : {
122 9 : NS_IF_RELEASE(mGB2312Decoder);
123 9 : NS_IF_RELEASE(mEUCKRDecoder);
124 9 : NS_IF_RELEASE(mISO88597Decoder);
125 36 : }
126 :
127 : NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
128 : PRUnichar * aDest, PRInt32 * aDestLength) ;
129 128 : NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
130 : PRInt32 * aDestLength)
131 : {
132 128 : *aDestLength = aSrcLength;
133 128 : return NS_OK;
134 : }
135 0 : NS_IMETHOD Reset()
136 : {
137 0 : mState = mState_ASCII;
138 0 : mLastLegalState = mState_ASCII;
139 0 : mRunLength = 0;
140 0 : return NS_OK;
141 : }
142 :
143 : private:
144 : enum {
145 : mState_ASCII,
146 : mState_ESC,
147 : mState_ESC_28,
148 : mState_ESC_24,
149 : mState_ESC_24_28,
150 : mState_JISX0201_1976Roman,
151 : mState_JISX0201_1976Kana,
152 : mState_JISX0208_1978,
153 : mState_GB2312_1980,
154 : mState_JISX0208_1983,
155 : mState_KSC5601_1987,
156 : mState_JISX0212_1990,
157 : mState_JISX0208_1978_2ndbyte,
158 : mState_GB2312_1980_2ndbyte,
159 : mState_JISX0208_1983_2ndbyte,
160 : mState_KSC5601_1987_2ndbyte,
161 : mState_JISX0212_1990_2ndbyte,
162 : mState_ESC_2e,
163 : mState_ESC_4e,
164 : mState_ERROR
165 : } mState, mLastLegalState;
166 : PRInt32 mData;
167 : PRInt32 mRunLength; // the length of a non-ASCII run
168 : enum {
169 : G2_unknown,
170 : G2_ISO88591,
171 : G2_ISO88597
172 : } G2charset;
173 : nsIUnicodeDecoder *mGB2312Decoder;
174 : nsIUnicodeDecoder *mEUCKRDecoder;
175 : nsIUnicodeDecoder *mISO88597Decoder;
176 : };
177 : #endif // nsShiftJISToUnicode_h__
|