File: nsMBCSSM.cpp

package info (click to toggle)
texmaker 5.1.3%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 80,340 kB
  • sloc: cpp: 429,691; ansic: 192,386; python: 1,935; xml: 1,724; asm: 205; sh: 176; makefile: 46
file content (618 lines) | stat: -rw-r--r-- 24,042 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*  -*- C++ -*-
*  Copyright (C) 1998 <developer@mozilla.org>
*
*
*  Permission is hereby granted, free of charge, to any person obtaining
*  a copy of this software and associated documentation files (the
*  "Software"), to deal in the Software without restriction, including
*  without limitation the rights to use, copy, modify, merge, publish,
*  distribute, sublicense, and/or sell copies of the Software, and to
*  permit persons to whom the Software is furnished to do so, subject to
*  the following conditions:
*
*  The above copyright notice and this permission notice shall be included 
*  in all copies or substantial portions of the Software.
*
*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
*  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
*  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
*  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
*  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "nsCodingStateMachine.h"

/*
Modification from frank tang's original work:
. 0x00 is allowed as a legal character. Since some web pages contains this char in 
  text stream.
*/

// BIG5 

namespace qencodingprober {
static unsigned int BIG5_cls [ 256 / 8 ] = {
//PCK4BITS(0,1,1,1,1,1,1,1),  // 00 - 07 
PCK4BITS(1,1,1,1,1,1,1,1),  // 00 - 07    //allow 0x00 as legal value
PCK4BITS(1,1,1,1,1,1,0,0),  // 08 - 0f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 10 - 17 
PCK4BITS(1,1,1,0,1,1,1,1),  // 18 - 1f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 20 - 27 
PCK4BITS(1,1,1,1,1,1,1,1),  // 28 - 2f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 30 - 37 
PCK4BITS(1,1,1,1,1,1,1,1),  // 38 - 3f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 40 - 47 
PCK4BITS(2,2,2,2,2,2,2,2),  // 48 - 4f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 50 - 57 
PCK4BITS(2,2,2,2,2,2,2,2),  // 58 - 5f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 60 - 67 
PCK4BITS(2,2,2,2,2,2,2,2),  // 68 - 6f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 70 - 77 
PCK4BITS(2,2,2,2,2,2,2,1),  // 78 - 7f 
PCK4BITS(4,4,4,4,4,4,4,4),  // 80 - 87 
PCK4BITS(4,4,4,4,4,4,4,4),  // 88 - 8f 
PCK4BITS(4,4,4,4,4,4,4,4),  // 90 - 97 
PCK4BITS(4,4,4,4,4,4,4,4),  // 98 - 9f 
PCK4BITS(4,3,3,3,3,3,3,3),  // a0 - a7 
PCK4BITS(3,3,3,3,3,3,3,3),  // a8 - af 
PCK4BITS(3,3,3,3,3,3,3,3),  // b0 - b7 
PCK4BITS(3,3,3,3,3,3,3,3),  // b8 - bf 
PCK4BITS(3,3,3,3,3,3,3,3),  // c0 - c7 
PCK4BITS(3,3,3,3,3,3,3,3),  // c8 - cf 
PCK4BITS(3,3,3,3,3,3,3,3),  // d0 - d7 
PCK4BITS(3,3,3,3,3,3,3,3),  // d8 - df 
PCK4BITS(3,3,3,3,3,3,3,3),  // e0 - e7 
PCK4BITS(3,3,3,3,3,3,3,3),  // e8 - ef 
PCK4BITS(3,3,3,3,3,3,3,3),  // f0 - f7 
PCK4BITS(3,3,3,3,3,3,3,0)   // f8 - ff 
};


static unsigned int BIG5_st [ 3] = {
PCK4BITS(eError,eStart,eStart,     3,eError,eError,eError,eError),//00-07 
PCK4BITS(eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError),//08-0f 
PCK4BITS(eError,eStart,eStart,eStart,eStart,eStart,eStart,eStart) //10-17 
};

static const unsigned int Big5CharLenTable[] = {0, 1, 1, 2, 0};

SMModel Big5SMModel = {
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, BIG5_cls },
    5,
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, BIG5_st },
  Big5CharLenTable,
  "Big5",
};

static unsigned int EUCJP_cls [ 256 / 8 ] = {
//PCK4BITS(5,4,4,4,4,4,4,4),  // 00 - 07 
PCK4BITS(4,4,4,4,4,4,4,4),  // 00 - 07 
PCK4BITS(4,4,4,4,4,4,5,5),  // 08 - 0f 
PCK4BITS(4,4,4,4,4,4,4,4),  // 10 - 17 
PCK4BITS(4,4,4,5,4,4,4,4),  // 18 - 1f 
PCK4BITS(4,4,4,4,4,4,4,4),  // 20 - 27 
PCK4BITS(4,4,4,4,4,4,4,4),  // 28 - 2f 
PCK4BITS(4,4,4,4,4,4,4,4),  // 30 - 37 
PCK4BITS(4,4,4,4,4,4,4,4),  // 38 - 3f 
PCK4BITS(4,4,4,4,4,4,4,4),  // 40 - 47 
PCK4BITS(4,4,4,4,4,4,4,4),  // 48 - 4f 
PCK4BITS(4,4,4,4,4,4,4,4),  // 50 - 57 
PCK4BITS(4,4,4,4,4,4,4,4),  // 58 - 5f 
PCK4BITS(4,4,4,4,4,4,4,4),  // 60 - 67 
PCK4BITS(4,4,4,4,4,4,4,4),  // 68 - 6f 
PCK4BITS(4,4,4,4,4,4,4,4),  // 70 - 77 
PCK4BITS(4,4,4,4,4,4,4,4),  // 78 - 7f 
PCK4BITS(5,5,5,5,5,5,5,5),  // 80 - 87 
PCK4BITS(5,5,5,5,5,5,1,3),  // 88 - 8f 
PCK4BITS(5,5,5,5,5,5,5,5),  // 90 - 97 
PCK4BITS(5,5,5,5,5,5,5,5),  // 98 - 9f 
PCK4BITS(5,2,2,2,2,2,2,2),  // a0 - a7 
PCK4BITS(2,2,2,2,2,2,2,2),  // a8 - af 
PCK4BITS(2,2,2,2,2,2,2,2),  // b0 - b7 
PCK4BITS(2,2,2,2,2,2,2,2),  // b8 - bf 
PCK4BITS(2,2,2,2,2,2,2,2),  // c0 - c7 
PCK4BITS(2,2,2,2,2,2,2,2),  // c8 - cf 
PCK4BITS(2,2,2,2,2,2,2,2),  // d0 - d7 
PCK4BITS(2,2,2,2,2,2,2,2),  // d8 - df 
PCK4BITS(0,0,0,0,0,0,0,0),  // e0 - e7 
PCK4BITS(0,0,0,0,0,0,0,0),  // e8 - ef 
PCK4BITS(0,0,0,0,0,0,0,0),  // f0 - f7 
PCK4BITS(0,0,0,0,0,0,0,5)   // f8 - ff 
};


static unsigned int EUCJP_st [ 5] = {
PCK4BITS(     3,     4,     3,     5,eStart,eError,eError,eError),//00-07 
PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f 
PCK4BITS(eItsMe,eItsMe,eStart,eError,eStart,eError,eError,eError),//10-17 
PCK4BITS(eError,eError,eStart,eError,eError,eError,     3,eError),//18-1f 
PCK4BITS(     3,eError,eError,eError,eStart,eStart,eStart,eStart) //20-27 
};

static const unsigned int EUCJPCharLenTable[] = {2, 2, 2, 3, 1, 0};

SMModel EUCJPSMModel = {
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCJP_cls },
   6,
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCJP_st },
  EUCJPCharLenTable,
  "EUC-JP",
};

static unsigned int EUCKR_cls [ 256 / 8 ] = {
//PCK4BITS(0,1,1,1,1,1,1,1),  // 00 - 07 
PCK4BITS(1,1,1,1,1,1,1,1),  // 00 - 07 
PCK4BITS(1,1,1,1,1,1,0,0),  // 08 - 0f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 10 - 17 
PCK4BITS(1,1,1,0,1,1,1,1),  // 18 - 1f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 20 - 27 
PCK4BITS(1,1,1,1,1,1,1,1),  // 28 - 2f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 30 - 37 
PCK4BITS(1,1,1,1,1,1,1,1),  // 38 - 3f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 40 - 47 
PCK4BITS(1,1,1,1,1,1,1,1),  // 48 - 4f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 50 - 57 
PCK4BITS(1,1,1,1,1,1,1,1),  // 58 - 5f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 60 - 67 
PCK4BITS(1,1,1,1,1,1,1,1),  // 68 - 6f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 70 - 77 
PCK4BITS(1,1,1,1,1,1,1,1),  // 78 - 7f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 80 - 87 
PCK4BITS(0,0,0,0,0,0,0,0),  // 88 - 8f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 90 - 97 
PCK4BITS(0,0,0,0,0,0,0,0),  // 98 - 9f 
PCK4BITS(0,2,2,2,2,2,2,2),  // a0 - a7 
PCK4BITS(2,2,2,2,2,3,3,3),  // a8 - af 
PCK4BITS(2,2,2,2,2,2,2,2),  // b0 - b7 
PCK4BITS(2,2,2,2,2,2,2,2),  // b8 - bf 
PCK4BITS(2,2,2,2,2,2,2,2),  // c0 - c7 
PCK4BITS(2,3,2,2,2,2,2,2),  // c8 - cf 
PCK4BITS(2,2,2,2,2,2,2,2),  // d0 - d7 
PCK4BITS(2,2,2,2,2,2,2,2),  // d8 - df 
PCK4BITS(2,2,2,2,2,2,2,2),  // e0 - e7 
PCK4BITS(2,2,2,2,2,2,2,2),  // e8 - ef 
PCK4BITS(2,2,2,2,2,2,2,2),  // f0 - f7 
PCK4BITS(2,2,2,2,2,2,2,0)   // f8 - ff 
};


static unsigned int EUCKR_st [ 2] = {
PCK4BITS(eError,eStart,     3,eError,eError,eError,eError,eError),//00-07 
PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart,eStart) //08-0f 
};

static const unsigned int EUCKRCharLenTable[] = {0, 1, 2, 0};

SMModel EUCKRSMModel = {
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCKR_cls },
  4,
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCKR_st },
  EUCKRCharLenTable,
  "EUC-KR",
};

static unsigned int EUCTW_cls [ 256 / 8 ] = {
//PCK4BITS(0,2,2,2,2,2,2,2),  // 00 - 07 
PCK4BITS(2,2,2,2,2,2,2,2),  // 00 - 07 
PCK4BITS(2,2,2,2,2,2,0,0),  // 08 - 0f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 10 - 17 
PCK4BITS(2,2,2,0,2,2,2,2),  // 18 - 1f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 20 - 27 
PCK4BITS(2,2,2,2,2,2,2,2),  // 28 - 2f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 30 - 37 
PCK4BITS(2,2,2,2,2,2,2,2),  // 38 - 3f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 40 - 47 
PCK4BITS(2,2,2,2,2,2,2,2),  // 48 - 4f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 50 - 57 
PCK4BITS(2,2,2,2,2,2,2,2),  // 58 - 5f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 60 - 67 
PCK4BITS(2,2,2,2,2,2,2,2),  // 68 - 6f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 70 - 77 
PCK4BITS(2,2,2,2,2,2,2,2),  // 78 - 7f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 80 - 87 
PCK4BITS(0,0,0,0,0,0,6,0),  // 88 - 8f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 90 - 97 
PCK4BITS(0,0,0,0,0,0,0,0),  // 98 - 9f 
PCK4BITS(0,3,4,4,4,4,4,4),  // a0 - a7 
PCK4BITS(5,5,1,1,1,1,1,1),  // a8 - af 
PCK4BITS(1,1,1,1,1,1,1,1),  // b0 - b7 
PCK4BITS(1,1,1,1,1,1,1,1),  // b8 - bf 
PCK4BITS(1,1,3,1,3,3,3,3),  // c0 - c7 
PCK4BITS(3,3,3,3,3,3,3,3),  // c8 - cf 
PCK4BITS(3,3,3,3,3,3,3,3),  // d0 - d7 
PCK4BITS(3,3,3,3,3,3,3,3),  // d8 - df 
PCK4BITS(3,3,3,3,3,3,3,3),  // e0 - e7 
PCK4BITS(3,3,3,3,3,3,3,3),  // e8 - ef 
PCK4BITS(3,3,3,3,3,3,3,3),  // f0 - f7 
PCK4BITS(3,3,3,3,3,3,3,0)   // f8 - ff 
};


static unsigned int EUCTW_st [ 6] = {
PCK4BITS(eError,eError,eStart,     3,     3,     3,     4,eError),//00-07 
PCK4BITS(eError,eError,eError,eError,eError,eError,eItsMe,eItsMe),//08-0f 
PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError,eStart,eError),//10-17 
PCK4BITS(eStart,eStart,eStart,eError,eError,eError,eError,eError),//18-1f 
PCK4BITS(     5,eError,eError,eError,eStart,eError,eStart,eStart),//20-27 
PCK4BITS(eStart,eError,eStart,eStart,eStart,eStart,eStart,eStart) //28-2f 
};

static const unsigned int EUCTWCharLenTable[] = {0, 0, 1, 2, 2, 2, 3};

SMModel EUCTWSMModel = {
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCTW_cls },
   7,
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCTW_st },
  EUCTWCharLenTable,
  "x-euc-tw",
};

/* obsolete GB2312 by gb18030
static unsigned int GB2312_cls [ 256 / 8 ] = {
//PCK4BITS(0,1,1,1,1,1,1,1),  // 00 - 07 
PCK4BITS(1,1,1,1,1,1,1,1),  // 00 - 07 
PCK4BITS(1,1,1,1,1,1,0,0),  // 08 - 0f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 10 - 17 
PCK4BITS(1,1,1,0,1,1,1,1),  // 18 - 1f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 20 - 27 
PCK4BITS(1,1,1,1,1,1,1,1),  // 28 - 2f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 30 - 37 
PCK4BITS(1,1,1,1,1,1,1,1),  // 38 - 3f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 40 - 47 
PCK4BITS(1,1,1,1,1,1,1,1),  // 48 - 4f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 50 - 57 
PCK4BITS(1,1,1,1,1,1,1,1),  // 58 - 5f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 60 - 67 
PCK4BITS(1,1,1,1,1,1,1,1),  // 68 - 6f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 70 - 77 
PCK4BITS(1,1,1,1,1,1,1,1),  // 78 - 7f 
PCK4BITS(1,0,0,0,0,0,0,0),  // 80 - 87 
PCK4BITS(0,0,0,0,0,0,0,0),  // 88 - 8f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 90 - 97 
PCK4BITS(0,0,0,0,0,0,0,0),  // 98 - 9f 
PCK4BITS(0,2,2,2,2,2,2,2),  // a0 - a7 
PCK4BITS(2,2,3,3,3,3,3,3),  // a8 - af 
PCK4BITS(2,2,2,2,2,2,2,2),  // b0 - b7 
PCK4BITS(2,2,2,2,2,2,2,2),  // b8 - bf 
PCK4BITS(2,2,2,2,2,2,2,2),  // c0 - c7 
PCK4BITS(2,2,2,2,2,2,2,2),  // c8 - cf 
PCK4BITS(2,2,2,2,2,2,2,2),  // d0 - d7 
PCK4BITS(2,2,2,2,2,2,2,2),  // d8 - df 
PCK4BITS(2,2,2,2,2,2,2,2),  // e0 - e7 
PCK4BITS(2,2,2,2,2,2,2,2),  // e8 - ef 
PCK4BITS(2,2,2,2,2,2,2,2),  // f0 - f7 
PCK4BITS(2,2,2,2,2,2,2,0)   // f8 - ff 
};


static unsigned int GB2312_st [ 2] = {
PCK4BITS(eError,eStart,     3,eError,eError,eError,eError,eError),//00-07 
PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart,eStart) //08-0f 
};

static const unsigned int GB2312CharLenTable[] = {0, 1, 2, 0};

SMModel GB2312SMModel = {
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB2312_cls },
   4,
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB2312_st },
  GB2312CharLenTable,
  "GB2312",
};
*/

// the following state machine data was created by perl script in 
// intl/chardet/tools. It should be the same as in PSM detector.
static unsigned int GB18030_cls [ 256 / 8 ] = {
PCK4BITS(1,1,1,1,1,1,1,1),  // 00 - 07 
PCK4BITS(1,1,1,1,1,1,0,0),  // 08 - 0f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 10 - 17 
PCK4BITS(1,1,1,0,1,1,1,1),  // 18 - 1f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 20 - 27 
PCK4BITS(1,1,1,1,1,1,1,1),  // 28 - 2f 
PCK4BITS(3,3,3,3,3,3,3,3),  // 30 - 37 
PCK4BITS(3,3,1,1,1,1,1,1),  // 38 - 3f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 40 - 47 
PCK4BITS(2,2,2,2,2,2,2,2),  // 48 - 4f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 50 - 57 
PCK4BITS(2,2,2,2,2,2,2,2),  // 58 - 5f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 60 - 67 
PCK4BITS(2,2,2,2,2,2,2,2),  // 68 - 6f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 70 - 77 
PCK4BITS(2,2,2,2,2,2,2,4),  // 78 - 7f 
PCK4BITS(5,6,6,6,6,6,6,6),  // 80 - 87 
PCK4BITS(6,6,6,6,6,6,6,6),  // 88 - 8f 
PCK4BITS(6,6,6,6,6,6,6,6),  // 90 - 97 
PCK4BITS(6,6,6,6,6,6,6,6),  // 98 - 9f 
PCK4BITS(6,6,6,6,6,6,6,6),  // a0 - a7 
PCK4BITS(6,6,6,6,6,6,6,6),  // a8 - af 
PCK4BITS(6,6,6,6,6,6,6,6),  // b0 - b7 
PCK4BITS(6,6,6,6,6,6,6,6),  // b8 - bf 
PCK4BITS(6,6,6,6,6,6,6,6),  // c0 - c7 
PCK4BITS(6,6,6,6,6,6,6,6),  // c8 - cf 
PCK4BITS(6,6,6,6,6,6,6,6),  // d0 - d7 
PCK4BITS(6,6,6,6,6,6,6,6),  // d8 - df 
PCK4BITS(6,6,6,6,6,6,6,6),  // e0 - e7 
PCK4BITS(6,6,6,6,6,6,6,6),  // e8 - ef 
PCK4BITS(6,6,6,6,6,6,6,6),  // f0 - f7 
PCK4BITS(6,6,6,6,6,6,6,0)   // f8 - ff 
};


static unsigned int GB18030_st [ 6] = {
PCK4BITS(eError,eStart,eStart,eStart,eStart,eStart,     3,eError),//00-07 
PCK4BITS(eError,eError,eError,eError,eError,eError,eItsMe,eItsMe),//08-0f 
PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart),//10-17 
PCK4BITS(     4,eError,eStart,eStart,eError,eError,eError,eError),//18-1f 
PCK4BITS(eError,eError,     5,eError,eError,eError,eItsMe,eError),//20-27 
PCK4BITS(eError,eError,eStart,eStart,eStart,eStart,eStart,eStart) //28-2f 
};

// To be accurate, the length of class 6 can be either 2 or 4. 
// But it is not necessary to discriminate between the two since 
// it is used for frequency analysis only, and we are validing 
// each code range there as well. So it is safe to set it to be 
// 2 here. 
static const unsigned int GB18030CharLenTable[] = {0, 1, 1, 1, 1, 1, 2};

SMModel GB18030SMModel = {
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB18030_cls },
   7,
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB18030_st },
  GB18030CharLenTable,
  "GB18030",
};

// sjis

static unsigned int SJIS_cls [ 256 / 8 ] = {
//PCK4BITS(0,1,1,1,1,1,1,1),  // 00 - 07 
PCK4BITS(1,1,1,1,1,1,1,1),  // 00 - 07 
PCK4BITS(1,1,1,1,1,1,0,0),  // 08 - 0f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 10 - 17 
PCK4BITS(1,1,1,0,1,1,1,1),  // 18 - 1f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 20 - 27 
PCK4BITS(1,1,1,1,1,1,1,1),  // 28 - 2f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 30 - 37 
PCK4BITS(1,1,1,1,1,1,1,1),  // 38 - 3f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 40 - 47 
PCK4BITS(2,2,2,2,2,2,2,2),  // 48 - 4f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 50 - 57 
PCK4BITS(2,2,2,2,2,2,2,2),  // 58 - 5f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 60 - 67 
PCK4BITS(2,2,2,2,2,2,2,2),  // 68 - 6f 
PCK4BITS(2,2,2,2,2,2,2,2),  // 70 - 77 
PCK4BITS(2,2,2,2,2,2,2,1),  // 78 - 7f 
PCK4BITS(3,3,3,3,3,3,3,3),  // 80 - 87 
PCK4BITS(3,3,3,3,3,3,3,3),  // 88 - 8f 
PCK4BITS(3,3,3,3,3,3,3,3),  // 90 - 97 
PCK4BITS(3,3,3,3,3,3,3,3),  // 98 - 9f 
//0xa0 is illegal in sjis encoding, but some pages does 
//contain such byte. We need to be more error forgiven.
PCK4BITS(2,2,2,2,2,2,2,2),  // a0 - a7     
PCK4BITS(2,2,2,2,2,2,2,2),  // a8 - af 
PCK4BITS(2,2,2,2,2,2,2,2),  // b0 - b7 
PCK4BITS(2,2,2,2,2,2,2,2),  // b8 - bf 
PCK4BITS(2,2,2,2,2,2,2,2),  // c0 - c7 
PCK4BITS(2,2,2,2,2,2,2,2),  // c8 - cf 
PCK4BITS(2,2,2,2,2,2,2,2),  // d0 - d7 
PCK4BITS(2,2,2,2,2,2,2,2),  // d8 - df 
PCK4BITS(3,3,3,3,3,3,3,3),  // e0 - e7 
PCK4BITS(3,3,3,3,3,4,4,4),  // e8 - ef 
PCK4BITS(4,4,4,4,4,4,4,4),  // f0 - f7 
PCK4BITS(4,4,4,4,4,0,0,0)   // f8 - ff 
};


static unsigned int SJIS_st [ 3] = {
PCK4BITS(eError,eStart,eStart,     3,eError,eError,eError,eError),//00-07 
PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f 
PCK4BITS(eItsMe,eItsMe,eError,eError,eStart,eStart,eStart,eStart) //10-17 
};

static const unsigned int SJISCharLenTable[] = {0, 1, 1, 2, 0, 0};

SMModel SJISSMModel = {
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, SJIS_cls },
   6,
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, SJIS_st },
  SJISCharLenTable,
  "Shift_JIS",
};


static unsigned int UCS2BE_cls [ 256 / 8 ] = {
PCK4BITS(0,0,0,0,0,0,0,0),  // 00 - 07 
PCK4BITS(0,0,1,0,0,2,0,0),  // 08 - 0f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 10 - 17 
PCK4BITS(0,0,0,3,0,0,0,0),  // 18 - 1f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 20 - 27 
PCK4BITS(0,3,3,3,3,3,0,0),  // 28 - 2f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 30 - 37 
PCK4BITS(0,0,0,0,0,0,0,0),  // 38 - 3f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 40 - 47 
PCK4BITS(0,0,0,0,0,0,0,0),  // 48 - 4f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 50 - 57 
PCK4BITS(0,0,0,0,0,0,0,0),  // 58 - 5f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 60 - 67 
PCK4BITS(0,0,0,0,0,0,0,0),  // 68 - 6f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 70 - 77 
PCK4BITS(0,0,0,0,0,0,0,0),  // 78 - 7f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 80 - 87 
PCK4BITS(0,0,0,0,0,0,0,0),  // 88 - 8f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 90 - 97 
PCK4BITS(0,0,0,0,0,0,0,0),  // 98 - 9f 
PCK4BITS(0,0,0,0,0,0,0,0),  // a0 - a7 
PCK4BITS(0,0,0,0,0,0,0,0),  // a8 - af 
PCK4BITS(0,0,0,0,0,0,0,0),  // b0 - b7 
PCK4BITS(0,0,0,0,0,0,0,0),  // b8 - bf 
PCK4BITS(0,0,0,0,0,0,0,0),  // c0 - c7 
PCK4BITS(0,0,0,0,0,0,0,0),  // c8 - cf 
PCK4BITS(0,0,0,0,0,0,0,0),  // d0 - d7 
PCK4BITS(0,0,0,0,0,0,0,0),  // d8 - df 
PCK4BITS(0,0,0,0,0,0,0,0),  // e0 - e7 
PCK4BITS(0,0,0,0,0,0,0,0),  // e8 - ef 
PCK4BITS(0,0,0,0,0,0,0,0),  // f0 - f7 
PCK4BITS(0,0,0,0,0,0,4,5)   // f8 - ff 
};


static unsigned int UCS2BE_st [ 7] = {
PCK4BITS(     5,     7,     7,eError,     4,     3,eError,eError),//00-07 
PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f 
PCK4BITS(eItsMe,eItsMe,     6,     6,     6,     6,eError,eError),//10-17 
PCK4BITS(     6,     6,     6,     6,     6,eItsMe,     6,     6),//18-1f 
PCK4BITS(     6,     6,     6,     6,     5,     7,     7,eError),//20-27 
PCK4BITS(     5,     8,     6,     6,eError,     6,     6,     6),//28-2f 
PCK4BITS(     6,     6,     6,     6,eError,eError,eStart,eStart) //30-37 
};

static const unsigned int UCS2BECharLenTable[] = {2, 2, 2, 0, 2, 2};

SMModel UCS2BESMModel = {
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UCS2BE_cls },
   6,
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UCS2BE_st },
  UCS2BECharLenTable,
  "UTF-16BE",
};

static unsigned int UCS2LE_cls [ 256 / 8 ] = {
PCK4BITS(0,0,0,0,0,0,0,0),  // 00 - 07 
PCK4BITS(0,0,1,0,0,2,0,0),  // 08 - 0f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 10 - 17 
PCK4BITS(0,0,0,3,0,0,0,0),  // 18 - 1f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 20 - 27 
PCK4BITS(0,3,3,3,3,3,0,0),  // 28 - 2f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 30 - 37 
PCK4BITS(0,0,0,0,0,0,0,0),  // 38 - 3f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 40 - 47 
PCK4BITS(0,0,0,0,0,0,0,0),  // 48 - 4f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 50 - 57 
PCK4BITS(0,0,0,0,0,0,0,0),  // 58 - 5f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 60 - 67 
PCK4BITS(0,0,0,0,0,0,0,0),  // 68 - 6f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 70 - 77 
PCK4BITS(0,0,0,0,0,0,0,0),  // 78 - 7f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 80 - 87 
PCK4BITS(0,0,0,0,0,0,0,0),  // 88 - 8f 
PCK4BITS(0,0,0,0,0,0,0,0),  // 90 - 97 
PCK4BITS(0,0,0,0,0,0,0,0),  // 98 - 9f 
PCK4BITS(0,0,0,0,0,0,0,0),  // a0 - a7 
PCK4BITS(0,0,0,0,0,0,0,0),  // a8 - af 
PCK4BITS(0,0,0,0,0,0,0,0),  // b0 - b7 
PCK4BITS(0,0,0,0,0,0,0,0),  // b8 - bf 
PCK4BITS(0,0,0,0,0,0,0,0),  // c0 - c7 
PCK4BITS(0,0,0,0,0,0,0,0),  // c8 - cf 
PCK4BITS(0,0,0,0,0,0,0,0),  // d0 - d7 
PCK4BITS(0,0,0,0,0,0,0,0),  // d8 - df 
PCK4BITS(0,0,0,0,0,0,0,0),  // e0 - e7 
PCK4BITS(0,0,0,0,0,0,0,0),  // e8 - ef 
PCK4BITS(0,0,0,0,0,0,0,0),  // f0 - f7 
PCK4BITS(0,0,0,0,0,0,4,5)   // f8 - ff 
};


static unsigned int UCS2LE_st [ 7] = {
PCK4BITS(     6,     6,     7,     6,     4,     3,eError,eError),//00-07 
PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f 
PCK4BITS(eItsMe,eItsMe,     5,     5,     5,eError,eItsMe,eError),//10-17 
PCK4BITS(     5,     5,     5,eError,     5,eError,     6,     6),//18-1f 
PCK4BITS(     7,     6,     8,     8,     5,     5,     5,eError),//20-27 
PCK4BITS(     5,     5,     5,eError,eError,eError,     5,     5),//28-2f 
PCK4BITS(     5,     5,     5,eError,     5,eError,eStart,eStart) //30-37 
};

static const unsigned int UCS2LECharLenTable[] = {2, 2, 2, 2, 2, 2};

SMModel UCS2LESMModel = {
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UCS2LE_cls },
   6,
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UCS2LE_st },
  UCS2LECharLenTable,
  "UTF-16LE",
};


static unsigned int UTF8_cls [ 256 / 8 ] = {
//PCK4BITS(0,1,1,1,1,1,1,1),  // 00 - 07 
PCK4BITS(1,1,1,1,1,1,1,1),  // 00 - 07  //allow 0x00 as a legal value
PCK4BITS(1,1,1,1,1,1,0,0),  // 08 - 0f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 10 - 17 
PCK4BITS(1,1,1,0,1,1,1,1),  // 18 - 1f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 20 - 27 
PCK4BITS(1,1,1,1,1,1,1,1),  // 28 - 2f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 30 - 37 
PCK4BITS(1,1,1,1,1,1,1,1),  // 38 - 3f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 40 - 47 
PCK4BITS(1,1,1,1,1,1,1,1),  // 48 - 4f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 50 - 57 
PCK4BITS(1,1,1,1,1,1,1,1),  // 58 - 5f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 60 - 67 
PCK4BITS(1,1,1,1,1,1,1,1),  // 68 - 6f 
PCK4BITS(1,1,1,1,1,1,1,1),  // 70 - 77 
PCK4BITS(1,1,1,1,1,1,1,1),  // 78 - 7f 
PCK4BITS(2,2,2,2,3,3,3,3),  // 80 - 87 
PCK4BITS(4,4,4,4,4,4,4,4),  // 88 - 8f 
PCK4BITS(4,4,4,4,4,4,4,4),  // 90 - 97 
PCK4BITS(4,4,4,4,4,4,4,4),  // 98 - 9f 
PCK4BITS(5,5,5,5,5,5,5,5),  // a0 - a7 
PCK4BITS(5,5,5,5,5,5,5,5),  // a8 - af 
PCK4BITS(5,5,5,5,5,5,5,5),  // b0 - b7 
PCK4BITS(5,5,5,5,5,5,5,5),  // b8 - bf 
PCK4BITS(0,0,6,6,6,6,6,6),  // c0 - c7 
PCK4BITS(6,6,6,6,6,6,6,6),  // c8 - cf 
PCK4BITS(6,6,6,6,6,6,6,6),  // d0 - d7 
PCK4BITS(6,6,6,6,6,6,6,6),  // d8 - df 
PCK4BITS(7,8,8,8,8,8,8,8),  // e0 - e7 
PCK4BITS(8,8,8,8,8,9,8,8),  // e8 - ef 
PCK4BITS(10,11,11,11,11,11,11,11),  // f0 - f7 
PCK4BITS(12,13,13,13,14,15,0,0)   // f8 - ff 
};


static unsigned int UTF8_st [ 26] = {
PCK4BITS(eError,eStart,eError,eError,eError,eError,     12,     10),//00-07 
PCK4BITS(     9,     11,     8,     7,     6,     5,     4,     3),//08-0f 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//10-17 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//18-1f 
PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe),//20-27 
PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe),//28-2f 
PCK4BITS(eError,eError,     5,     5,     5,     5,eError,eError),//30-37 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//38-3f 
PCK4BITS(eError,eError,eError,     5,     5,     5,eError,eError),//40-47 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//48-4f 
PCK4BITS(eError,eError,     7,     7,     7,     7,eError,eError),//50-57 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//58-5f 
PCK4BITS(eError,eError,eError,eError,     7,     7,eError,eError),//60-67 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//68-6f 
PCK4BITS(eError,eError,     9,     9,     9,     9,eError,eError),//70-77 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//78-7f 
PCK4BITS(eError,eError,eError,eError,eError,     9,eError,eError),//80-87 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//88-8f 
PCK4BITS(eError,eError,     12,     12,     12,     12,eError,eError),//90-97 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//98-9f 
PCK4BITS(eError,eError,eError,eError,eError,     12,eError,eError),//a0-a7 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//a8-af 
PCK4BITS(eError,eError,     12,     12,     12,eError,eError,eError),//b0-b7 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//b8-bf 
PCK4BITS(eError,eError,eStart,eStart,eStart,eStart,eError,eError),//c0-c7 
PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError) //c8-cf 
};

static const unsigned int UTF8CharLenTable[] = {0, 1, 0, 0, 0, 0, 2, 3, 
                            3, 3, 4, 4, 5, 5, 6, 6 };

SMModel UTF8SMModel = {
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UTF8_cls },
   16,
  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UTF8_st },
  UTF8CharLenTable,
  "UTF-8",
};
}