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
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/
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
15
* The Original Code is mozilla.org code.
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.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* 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.
36
* ***** END LICENSE BLOCK ***** */
37
#include "nsCodingStateMachine.h"
39
static PRUint32 HZ_cls[ 256 / 8 ] = {
40
PCK4BITS(1,0,0,0,0,0,0,0), // 00 - 07
41
PCK4BITS(0,0,0,0,0,0,0,0), // 08 - 0f
42
PCK4BITS(0,0,0,0,0,0,0,0), // 10 - 17
43
PCK4BITS(0,0,0,1,0,0,0,0), // 18 - 1f
44
PCK4BITS(0,0,0,0,0,0,0,0), // 20 - 27
45
PCK4BITS(0,0,0,0,0,0,0,0), // 28 - 2f
46
PCK4BITS(0,0,0,0,0,0,0,0), // 30 - 37
47
PCK4BITS(0,0,0,0,0,0,0,0), // 38 - 3f
48
PCK4BITS(0,0,0,0,0,0,0,0), // 40 - 47
49
PCK4BITS(0,0,0,0,0,0,0,0), // 48 - 4f
50
PCK4BITS(0,0,0,0,0,0,0,0), // 50 - 57
51
PCK4BITS(0,0,0,0,0,0,0,0), // 58 - 5f
52
PCK4BITS(0,0,0,0,0,0,0,0), // 60 - 67
53
PCK4BITS(0,0,0,0,0,0,0,0), // 68 - 6f
54
PCK4BITS(0,0,0,0,0,0,0,0), // 70 - 77
55
PCK4BITS(0,0,0,4,0,5,2,0), // 78 - 7f
56
PCK4BITS(1,1,1,1,1,1,1,1), // 80 - 87
57
PCK4BITS(1,1,1,1,1,1,1,1), // 88 - 8f
58
PCK4BITS(1,1,1,1,1,1,1,1), // 90 - 97
59
PCK4BITS(1,1,1,1,1,1,1,1), // 98 - 9f
60
PCK4BITS(1,1,1,1,1,1,1,1), // a0 - a7
61
PCK4BITS(1,1,1,1,1,1,1,1), // a8 - af
62
PCK4BITS(1,1,1,1,1,1,1,1), // b0 - b7
63
PCK4BITS(1,1,1,1,1,1,1,1), // b8 - bf
64
PCK4BITS(1,1,1,1,1,1,1,1), // c0 - c7
65
PCK4BITS(1,1,1,1,1,1,1,1), // c8 - cf
66
PCK4BITS(1,1,1,1,1,1,1,1), // d0 - d7
67
PCK4BITS(1,1,1,1,1,1,1,1), // d8 - df
68
PCK4BITS(1,1,1,1,1,1,1,1), // e0 - e7
69
PCK4BITS(1,1,1,1,1,1,1,1), // e8 - ef
70
PCK4BITS(1,1,1,1,1,1,1,1), // f0 - f7
71
PCK4BITS(1,1,1,1,1,1,1,1) // f8 - ff
75
static PRUint32 HZ_st [ 6] = {
76
PCK4BITS(eStart,eError, 3,eStart,eStart,eStart,eError,eError),//00-07
77
PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f
78
PCK4BITS(eItsMe,eItsMe,eError,eError,eStart,eStart, 4,eError),//10-17
79
PCK4BITS( 5,eError, 6,eError, 5, 5, 4,eError),//18-1f
80
PCK4BITS( 4,eError, 4, 4, 4,eError, 4,eError),//20-27
81
PCK4BITS( 4,eItsMe,eStart,eStart,eStart,eStart,eStart,eStart) //28-2f
84
static const PRUint32 HZCharLenTable[] = {0, 0, 0, 0, 0, 0};
87
{eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, HZ_cls },
89
{eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, HZ_st },
95
static PRUint32 ISO2022CN_cls [ 256 / 8 ] = {
96
PCK4BITS(2,0,0,0,0,0,0,0), // 00 - 07
97
PCK4BITS(0,0,0,0,0,0,0,0), // 08 - 0f
98
PCK4BITS(0,0,0,0,0,0,0,0), // 10 - 17
99
PCK4BITS(0,0,0,1,0,0,0,0), // 18 - 1f
100
PCK4BITS(0,0,0,0,0,0,0,0), // 20 - 27
101
PCK4BITS(0,3,0,0,0,0,0,0), // 28 - 2f
102
PCK4BITS(0,0,0,0,0,0,0,0), // 30 - 37
103
PCK4BITS(0,0,0,0,0,0,0,0), // 38 - 3f
104
PCK4BITS(0,0,0,4,0,0,0,0), // 40 - 47
105
PCK4BITS(0,0,0,0,0,0,0,0), // 48 - 4f
106
PCK4BITS(0,0,0,0,0,0,0,0), // 50 - 57
107
PCK4BITS(0,0,0,0,0,0,0,0), // 58 - 5f
108
PCK4BITS(0,0,0,0,0,0,0,0), // 60 - 67
109
PCK4BITS(0,0,0,0,0,0,0,0), // 68 - 6f
110
PCK4BITS(0,0,0,0,0,0,0,0), // 70 - 77
111
PCK4BITS(0,0,0,0,0,0,0,0), // 78 - 7f
112
PCK4BITS(2,2,2,2,2,2,2,2), // 80 - 87
113
PCK4BITS(2,2,2,2,2,2,2,2), // 88 - 8f
114
PCK4BITS(2,2,2,2,2,2,2,2), // 90 - 97
115
PCK4BITS(2,2,2,2,2,2,2,2), // 98 - 9f
116
PCK4BITS(2,2,2,2,2,2,2,2), // a0 - a7
117
PCK4BITS(2,2,2,2,2,2,2,2), // a8 - af
118
PCK4BITS(2,2,2,2,2,2,2,2), // b0 - b7
119
PCK4BITS(2,2,2,2,2,2,2,2), // b8 - bf
120
PCK4BITS(2,2,2,2,2,2,2,2), // c0 - c7
121
PCK4BITS(2,2,2,2,2,2,2,2), // c8 - cf
122
PCK4BITS(2,2,2,2,2,2,2,2), // d0 - d7
123
PCK4BITS(2,2,2,2,2,2,2,2), // d8 - df
124
PCK4BITS(2,2,2,2,2,2,2,2), // e0 - e7
125
PCK4BITS(2,2,2,2,2,2,2,2), // e8 - ef
126
PCK4BITS(2,2,2,2,2,2,2,2), // f0 - f7
127
PCK4BITS(2,2,2,2,2,2,2,2) // f8 - ff
131
static PRUint32 ISO2022CN_st [ 8] = {
132
PCK4BITS(eStart, 3,eError,eStart,eStart,eStart,eStart,eStart),//00-07
133
PCK4BITS(eStart,eError,eError,eError,eError,eError,eError,eError),//08-0f
134
PCK4BITS(eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe),//10-17
135
PCK4BITS(eItsMe,eItsMe,eItsMe,eError,eError,eError, 4,eError),//18-1f
136
PCK4BITS(eError,eError,eError,eItsMe,eError,eError,eError,eError),//20-27
137
PCK4BITS( 5, 6,eError,eError,eError,eError,eError,eError),//28-2f
138
PCK4BITS(eError,eError,eError,eItsMe,eError,eError,eError,eError),//30-37
139
PCK4BITS(eError,eError,eError,eError,eError,eItsMe,eError,eStart) //38-3f
142
static const PRUint32 ISO2022CNCharLenTable[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
144
SMModel ISO2022CNSMModel = {
145
{eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, ISO2022CN_cls },
147
{eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, ISO2022CN_st },
148
ISO2022CNCharLenTable,
152
static PRUint32 ISO2022JP_cls [ 256 / 8 ] = {
153
PCK4BITS(2,0,0,0,0,0,0,0), // 00 - 07
154
PCK4BITS(0,0,0,0,0,0,2,2), // 08 - 0f
155
PCK4BITS(0,0,0,0,0,0,0,0), // 10 - 17
156
PCK4BITS(0,0,0,1,0,0,0,0), // 18 - 1f
157
PCK4BITS(0,0,0,0,7,0,0,0), // 20 - 27
158
PCK4BITS(3,0,0,0,0,0,0,0), // 28 - 2f
159
PCK4BITS(0,0,0,0,0,0,0,0), // 30 - 37
160
PCK4BITS(0,0,0,0,0,0,0,0), // 38 - 3f
161
PCK4BITS(6,0,4,0,8,0,0,0), // 40 - 47
162
PCK4BITS(0,9,5,0,0,0,0,0), // 48 - 4f
163
PCK4BITS(0,0,0,0,0,0,0,0), // 50 - 57
164
PCK4BITS(0,0,0,0,0,0,0,0), // 58 - 5f
165
PCK4BITS(0,0,0,0,0,0,0,0), // 60 - 67
166
PCK4BITS(0,0,0,0,0,0,0,0), // 68 - 6f
167
PCK4BITS(0,0,0,0,0,0,0,0), // 70 - 77
168
PCK4BITS(0,0,0,0,0,0,0,0), // 78 - 7f
169
PCK4BITS(2,2,2,2,2,2,2,2), // 80 - 87
170
PCK4BITS(2,2,2,2,2,2,2,2), // 88 - 8f
171
PCK4BITS(2,2,2,2,2,2,2,2), // 90 - 97
172
PCK4BITS(2,2,2,2,2,2,2,2), // 98 - 9f
173
PCK4BITS(2,2,2,2,2,2,2,2), // a0 - a7
174
PCK4BITS(2,2,2,2,2,2,2,2), // a8 - af
175
PCK4BITS(2,2,2,2,2,2,2,2), // b0 - b7
176
PCK4BITS(2,2,2,2,2,2,2,2), // b8 - bf
177
PCK4BITS(2,2,2,2,2,2,2,2), // c0 - c7
178
PCK4BITS(2,2,2,2,2,2,2,2), // c8 - cf
179
PCK4BITS(2,2,2,2,2,2,2,2), // d0 - d7
180
PCK4BITS(2,2,2,2,2,2,2,2), // d8 - df
181
PCK4BITS(2,2,2,2,2,2,2,2), // e0 - e7
182
PCK4BITS(2,2,2,2,2,2,2,2), // e8 - ef
183
PCK4BITS(2,2,2,2,2,2,2,2), // f0 - f7
184
PCK4BITS(2,2,2,2,2,2,2,2) // f8 - ff
188
static PRUint32 ISO2022JP_st [ 9] = {
189
PCK4BITS(eStart, 3,eError,eStart,eStart,eStart,eStart,eStart),//00-07
190
PCK4BITS(eStart,eStart,eError,eError,eError,eError,eError,eError),//08-0f
191
PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//10-17
192
PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError,eError),//18-1f
193
PCK4BITS(eError, 5,eError,eError,eError, 4,eError,eError),//20-27
194
PCK4BITS(eError,eError,eError, 6,eItsMe,eError,eItsMe,eError),//28-2f
195
PCK4BITS(eError,eError,eError,eError,eError,eError,eItsMe,eItsMe),//30-37
196
PCK4BITS(eError,eError,eError,eItsMe,eError,eError,eError,eError),//38-3f
197
PCK4BITS(eError,eError,eError,eError,eItsMe,eError,eStart,eStart) //40-47
200
static const PRUint32 ISO2022JPCharLenTable[] = {0, 0, 0, 0, 0, 0, 0, 0};
202
SMModel ISO2022JPSMModel = {
203
{eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, ISO2022JP_cls },
205
{eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, ISO2022JP_st },
206
ISO2022JPCharLenTable,
210
static PRUint32 ISO2022KR_cls [ 256 / 8 ] = {
211
PCK4BITS(2,0,0,0,0,0,0,0), // 00 - 07
212
PCK4BITS(0,0,0,0,0,0,0,0), // 08 - 0f
213
PCK4BITS(0,0,0,0,0,0,0,0), // 10 - 17
214
PCK4BITS(0,0,0,1,0,0,0,0), // 18 - 1f
215
PCK4BITS(0,0,0,0,3,0,0,0), // 20 - 27
216
PCK4BITS(0,4,0,0,0,0,0,0), // 28 - 2f
217
PCK4BITS(0,0,0,0,0,0,0,0), // 30 - 37
218
PCK4BITS(0,0,0,0,0,0,0,0), // 38 - 3f
219
PCK4BITS(0,0,0,5,0,0,0,0), // 40 - 47
220
PCK4BITS(0,0,0,0,0,0,0,0), // 48 - 4f
221
PCK4BITS(0,0,0,0,0,0,0,0), // 50 - 57
222
PCK4BITS(0,0,0,0,0,0,0,0), // 58 - 5f
223
PCK4BITS(0,0,0,0,0,0,0,0), // 60 - 67
224
PCK4BITS(0,0,0,0,0,0,0,0), // 68 - 6f
225
PCK4BITS(0,0,0,0,0,0,0,0), // 70 - 77
226
PCK4BITS(0,0,0,0,0,0,0,0), // 78 - 7f
227
PCK4BITS(2,2,2,2,2,2,2,2), // 80 - 87
228
PCK4BITS(2,2,2,2,2,2,2,2), // 88 - 8f
229
PCK4BITS(2,2,2,2,2,2,2,2), // 90 - 97
230
PCK4BITS(2,2,2,2,2,2,2,2), // 98 - 9f
231
PCK4BITS(2,2,2,2,2,2,2,2), // a0 - a7
232
PCK4BITS(2,2,2,2,2,2,2,2), // a8 - af
233
PCK4BITS(2,2,2,2,2,2,2,2), // b0 - b7
234
PCK4BITS(2,2,2,2,2,2,2,2), // b8 - bf
235
PCK4BITS(2,2,2,2,2,2,2,2), // c0 - c7
236
PCK4BITS(2,2,2,2,2,2,2,2), // c8 - cf
237
PCK4BITS(2,2,2,2,2,2,2,2), // d0 - d7
238
PCK4BITS(2,2,2,2,2,2,2,2), // d8 - df
239
PCK4BITS(2,2,2,2,2,2,2,2), // e0 - e7
240
PCK4BITS(2,2,2,2,2,2,2,2), // e8 - ef
241
PCK4BITS(2,2,2,2,2,2,2,2), // f0 - f7
242
PCK4BITS(2,2,2,2,2,2,2,2) // f8 - ff
246
static PRUint32 ISO2022KR_st [ 5] = {
247
PCK4BITS(eStart, 3,eError,eStart,eStart,eStart,eError,eError),//00-07
248
PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f
249
PCK4BITS(eItsMe,eItsMe,eError,eError,eError, 4,eError,eError),//10-17
250
PCK4BITS(eError,eError,eError,eError, 5,eError,eError,eError),//18-1f
251
PCK4BITS(eError,eError,eError,eItsMe,eStart,eStart,eStart,eStart) //20-27
254
static const PRUint32 ISO2022KRCharLenTable[] = {0, 0, 0, 0, 0, 0};
256
SMModel ISO2022KRSMModel = {
257
{eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, ISO2022KR_cls },
259
{eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, ISO2022KR_st },
260
ISO2022KRCharLenTable,