extensions/universalchardet/src/base/nsMBCSSM.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extensions/universalchardet/src/base/nsMBCSSM.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,467 @@
     1.4 +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +#include "nsCodingStateMachine.h"
     1.9 +
    1.10 +/*
    1.11 +Modification from frank tang's original work:
    1.12 +. 0x00 is allowed as a legal character. Since some web pages contains this char in 
    1.13 +  text stream.
    1.14 +*/
    1.15 +
    1.16 +// BIG5 
    1.17 +
    1.18 +static const uint32_t BIG5_cls [ 256 / 8 ] = {
    1.19 +//PCK4BITS(0,1,1,1,1,1,1,1),  // 00 - 07 
    1.20 +PCK4BITS(1,1,1,1,1,1,1,1),  // 00 - 07    //allow 0x00 as legal value
    1.21 +PCK4BITS(1,1,1,1,1,1,0,0),  // 08 - 0f 
    1.22 +PCK4BITS(1,1,1,1,1,1,1,1),  // 10 - 17 
    1.23 +PCK4BITS(1,1,1,0,1,1,1,1),  // 18 - 1f 
    1.24 +PCK4BITS(1,1,1,1,1,1,1,1),  // 20 - 27 
    1.25 +PCK4BITS(1,1,1,1,1,1,1,1),  // 28 - 2f 
    1.26 +PCK4BITS(1,1,1,1,1,1,1,1),  // 30 - 37 
    1.27 +PCK4BITS(1,1,1,1,1,1,1,1),  // 38 - 3f 
    1.28 +PCK4BITS(2,2,2,2,2,2,2,2),  // 40 - 47 
    1.29 +PCK4BITS(2,2,2,2,2,2,2,2),  // 48 - 4f 
    1.30 +PCK4BITS(2,2,2,2,2,2,2,2),  // 50 - 57 
    1.31 +PCK4BITS(2,2,2,2,2,2,2,2),  // 58 - 5f 
    1.32 +PCK4BITS(2,2,2,2,2,2,2,2),  // 60 - 67 
    1.33 +PCK4BITS(2,2,2,2,2,2,2,2),  // 68 - 6f 
    1.34 +PCK4BITS(2,2,2,2,2,2,2,2),  // 70 - 77 
    1.35 +PCK4BITS(2,2,2,2,2,2,2,1),  // 78 - 7f 
    1.36 +PCK4BITS(4,4,4,4,4,4,4,4),  // 80 - 87 
    1.37 +PCK4BITS(4,4,4,4,4,4,4,4),  // 88 - 8f 
    1.38 +PCK4BITS(4,4,4,4,4,4,4,4),  // 90 - 97 
    1.39 +PCK4BITS(4,4,4,4,4,4,4,4),  // 98 - 9f 
    1.40 +PCK4BITS(4,3,3,3,3,3,3,3),  // a0 - a7 
    1.41 +PCK4BITS(3,3,3,3,3,3,3,3),  // a8 - af 
    1.42 +PCK4BITS(3,3,3,3,3,3,3,3),  // b0 - b7 
    1.43 +PCK4BITS(3,3,3,3,3,3,3,3),  // b8 - bf 
    1.44 +PCK4BITS(3,3,3,3,3,3,3,3),  // c0 - c7 
    1.45 +PCK4BITS(3,3,3,3,3,3,3,3),  // c8 - cf 
    1.46 +PCK4BITS(3,3,3,3,3,3,3,3),  // d0 - d7 
    1.47 +PCK4BITS(3,3,3,3,3,3,3,3),  // d8 - df 
    1.48 +PCK4BITS(3,3,3,3,3,3,3,3),  // e0 - e7 
    1.49 +PCK4BITS(3,3,3,3,3,3,3,3),  // e8 - ef 
    1.50 +PCK4BITS(3,3,3,3,3,3,3,3),  // f0 - f7 
    1.51 +PCK4BITS(3,3,3,3,3,3,3,0)   // f8 - ff 
    1.52 +};
    1.53 +
    1.54 +
    1.55 +static const uint32_t BIG5_st [ 3] = {
    1.56 +PCK4BITS(eError,eStart,eStart,     3,eError,eError,eError,eError),//00-07 
    1.57 +PCK4BITS(eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError),//08-0f 
    1.58 +PCK4BITS(eError,eStart,eStart,eStart,eStart,eStart,eStart,eStart) //10-17 
    1.59 +};
    1.60 +
    1.61 +static const uint32_t Big5CharLenTable[] = {0, 1, 1, 2, 0};
    1.62 +
    1.63 +SMModel const Big5SMModel = {
    1.64 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, BIG5_cls },
    1.65 +    5,
    1.66 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, BIG5_st },
    1.67 +  CHAR_LEN_TABLE(Big5CharLenTable),
    1.68 +  "Big5",
    1.69 +};
    1.70 +
    1.71 +static const uint32_t EUCJP_cls [ 256 / 8 ] = {
    1.72 +//PCK4BITS(5,4,4,4,4,4,4,4),  // 00 - 07 
    1.73 +PCK4BITS(4,4,4,4,4,4,4,4),  // 00 - 07 
    1.74 +PCK4BITS(4,4,4,4,4,4,5,5),  // 08 - 0f 
    1.75 +PCK4BITS(4,4,4,4,4,4,4,4),  // 10 - 17 
    1.76 +PCK4BITS(4,4,4,5,4,4,4,4),  // 18 - 1f 
    1.77 +PCK4BITS(4,4,4,4,4,4,4,4),  // 20 - 27 
    1.78 +PCK4BITS(4,4,4,4,4,4,4,4),  // 28 - 2f 
    1.79 +PCK4BITS(4,4,4,4,4,4,4,4),  // 30 - 37 
    1.80 +PCK4BITS(4,4,4,4,4,4,4,4),  // 38 - 3f 
    1.81 +PCK4BITS(4,4,4,4,4,4,4,4),  // 40 - 47 
    1.82 +PCK4BITS(4,4,4,4,4,4,4,4),  // 48 - 4f 
    1.83 +PCK4BITS(4,4,4,4,4,4,4,4),  // 50 - 57 
    1.84 +PCK4BITS(4,4,4,4,4,4,4,4),  // 58 - 5f 
    1.85 +PCK4BITS(4,4,4,4,4,4,4,4),  // 60 - 67 
    1.86 +PCK4BITS(4,4,4,4,4,4,4,4),  // 68 - 6f 
    1.87 +PCK4BITS(4,4,4,4,4,4,4,4),  // 70 - 77 
    1.88 +PCK4BITS(4,4,4,4,4,4,4,4),  // 78 - 7f 
    1.89 +PCK4BITS(5,5,5,5,5,5,5,5),  // 80 - 87 
    1.90 +PCK4BITS(5,5,5,5,5,5,1,3),  // 88 - 8f 
    1.91 +PCK4BITS(5,5,5,5,5,5,5,5),  // 90 - 97 
    1.92 +PCK4BITS(5,5,5,5,5,5,5,5),  // 98 - 9f 
    1.93 +PCK4BITS(5,2,2,2,2,2,2,2),  // a0 - a7 
    1.94 +PCK4BITS(2,2,2,2,2,2,2,2),  // a8 - af 
    1.95 +PCK4BITS(2,2,2,2,2,2,2,2),  // b0 - b7 
    1.96 +PCK4BITS(2,2,2,2,2,2,2,2),  // b8 - bf 
    1.97 +PCK4BITS(2,2,2,2,2,2,2,2),  // c0 - c7 
    1.98 +PCK4BITS(2,2,2,2,2,2,2,2),  // c8 - cf 
    1.99 +PCK4BITS(2,2,2,2,2,2,2,2),  // d0 - d7 
   1.100 +PCK4BITS(2,2,2,2,2,2,2,2),  // d8 - df 
   1.101 +PCK4BITS(0,0,0,0,0,0,0,0),  // e0 - e7 
   1.102 +PCK4BITS(0,0,0,0,0,0,0,0),  // e8 - ef 
   1.103 +PCK4BITS(0,0,0,0,0,0,0,0),  // f0 - f7 
   1.104 +PCK4BITS(0,0,0,0,0,0,0,5)   // f8 - ff 
   1.105 +};
   1.106 +
   1.107 +
   1.108 +static const uint32_t EUCJP_st [ 5] = {
   1.109 +PCK4BITS(     3,     4,     3,     5,eStart,eError,eError,eError),//00-07 
   1.110 +PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f 
   1.111 +PCK4BITS(eItsMe,eItsMe,eStart,eError,eStart,eError,eError,eError),//10-17 
   1.112 +PCK4BITS(eError,eError,eStart,eError,eError,eError,     3,eError),//18-1f 
   1.113 +PCK4BITS(     3,eError,eError,eError,eStart,eStart,eStart,eStart) //20-27 
   1.114 +};
   1.115 +
   1.116 +static const uint32_t EUCJPCharLenTable[] = {2, 2, 2, 3, 1, 0};
   1.117 +
   1.118 +const SMModel EUCJPSMModel = {
   1.119 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCJP_cls },
   1.120 +   6,
   1.121 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCJP_st },
   1.122 +  CHAR_LEN_TABLE(EUCJPCharLenTable),
   1.123 +  "EUC-JP",
   1.124 +};
   1.125 +
   1.126 +static const uint32_t EUCKR_cls [ 256 / 8 ] = {
   1.127 +//PCK4BITS(0,1,1,1,1,1,1,1),  // 00 - 07 
   1.128 +PCK4BITS(1,1,1,1,1,1,1,1),  // 00 - 07 
   1.129 +PCK4BITS(1,1,1,1,1,1,0,0),  // 08 - 0f 
   1.130 +PCK4BITS(1,1,1,1,1,1,1,1),  // 10 - 17 
   1.131 +PCK4BITS(1,1,1,0,1,1,1,1),  // 18 - 1f 
   1.132 +PCK4BITS(1,1,1,1,1,1,1,1),  // 20 - 27 
   1.133 +PCK4BITS(1,1,1,1,1,1,1,1),  // 28 - 2f 
   1.134 +PCK4BITS(1,1,1,1,1,1,1,1),  // 30 - 37 
   1.135 +PCK4BITS(1,1,1,1,1,1,1,1),  // 38 - 3f 
   1.136 +PCK4BITS(1,1,1,1,1,1,1,1),  // 40 - 47 
   1.137 +PCK4BITS(1,1,1,1,1,1,1,1),  // 48 - 4f 
   1.138 +PCK4BITS(1,1,1,1,1,1,1,1),  // 50 - 57 
   1.139 +PCK4BITS(1,1,1,1,1,1,1,1),  // 58 - 5f 
   1.140 +PCK4BITS(1,1,1,1,1,1,1,1),  // 60 - 67 
   1.141 +PCK4BITS(1,1,1,1,1,1,1,1),  // 68 - 6f 
   1.142 +PCK4BITS(1,1,1,1,1,1,1,1),  // 70 - 77 
   1.143 +PCK4BITS(1,1,1,1,1,1,1,1),  // 78 - 7f 
   1.144 +PCK4BITS(0,0,0,0,0,0,0,0),  // 80 - 87 
   1.145 +PCK4BITS(0,0,0,0,0,0,0,0),  // 88 - 8f 
   1.146 +PCK4BITS(0,0,0,0,0,0,0,0),  // 90 - 97 
   1.147 +PCK4BITS(0,0,0,0,0,0,0,0),  // 98 - 9f 
   1.148 +PCK4BITS(0,2,2,2,2,2,2,2),  // a0 - a7 
   1.149 +PCK4BITS(2,2,2,2,2,3,3,3),  // a8 - af 
   1.150 +PCK4BITS(2,2,2,2,2,2,2,2),  // b0 - b7 
   1.151 +PCK4BITS(2,2,2,2,2,2,2,2),  // b8 - bf 
   1.152 +PCK4BITS(2,2,2,2,2,2,2,2),  // c0 - c7 
   1.153 +PCK4BITS(2,3,2,2,2,2,2,2),  // c8 - cf 
   1.154 +PCK4BITS(2,2,2,2,2,2,2,2),  // d0 - d7 
   1.155 +PCK4BITS(2,2,2,2,2,2,2,2),  // d8 - df 
   1.156 +PCK4BITS(2,2,2,2,2,2,2,2),  // e0 - e7 
   1.157 +PCK4BITS(2,2,2,2,2,2,2,2),  // e8 - ef 
   1.158 +PCK4BITS(2,2,2,2,2,2,2,2),  // f0 - f7 
   1.159 +PCK4BITS(2,2,2,2,2,2,2,0)   // f8 - ff 
   1.160 +};
   1.161 +
   1.162 +
   1.163 +static const uint32_t EUCKR_st [ 2] = {
   1.164 +PCK4BITS(eError,eStart,     3,eError,eError,eError,eError,eError),//00-07 
   1.165 +PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart,eStart) //08-0f 
   1.166 +};
   1.167 +
   1.168 +static const uint32_t EUCKRCharLenTable[] = {0, 1, 2, 0};
   1.169 +
   1.170 +const SMModel EUCKRSMModel = {
   1.171 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCKR_cls },
   1.172 +  4,
   1.173 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCKR_st },
   1.174 +  CHAR_LEN_TABLE(EUCKRCharLenTable),
   1.175 +  "EUC-KR",
   1.176 +};
   1.177 +
   1.178 +static const uint32_t EUCTW_cls [ 256 / 8 ] = {
   1.179 +//PCK4BITS(0,2,2,2,2,2,2,2),  // 00 - 07 
   1.180 +PCK4BITS(2,2,2,2,2,2,2,2),  // 00 - 07 
   1.181 +PCK4BITS(2,2,2,2,2,2,0,0),  // 08 - 0f 
   1.182 +PCK4BITS(2,2,2,2,2,2,2,2),  // 10 - 17 
   1.183 +PCK4BITS(2,2,2,0,2,2,2,2),  // 18 - 1f 
   1.184 +PCK4BITS(2,2,2,2,2,2,2,2),  // 20 - 27 
   1.185 +PCK4BITS(2,2,2,2,2,2,2,2),  // 28 - 2f 
   1.186 +PCK4BITS(2,2,2,2,2,2,2,2),  // 30 - 37 
   1.187 +PCK4BITS(2,2,2,2,2,2,2,2),  // 38 - 3f 
   1.188 +PCK4BITS(2,2,2,2,2,2,2,2),  // 40 - 47 
   1.189 +PCK4BITS(2,2,2,2,2,2,2,2),  // 48 - 4f 
   1.190 +PCK4BITS(2,2,2,2,2,2,2,2),  // 50 - 57 
   1.191 +PCK4BITS(2,2,2,2,2,2,2,2),  // 58 - 5f 
   1.192 +PCK4BITS(2,2,2,2,2,2,2,2),  // 60 - 67 
   1.193 +PCK4BITS(2,2,2,2,2,2,2,2),  // 68 - 6f 
   1.194 +PCK4BITS(2,2,2,2,2,2,2,2),  // 70 - 77 
   1.195 +PCK4BITS(2,2,2,2,2,2,2,2),  // 78 - 7f 
   1.196 +PCK4BITS(0,0,0,0,0,0,0,0),  // 80 - 87 
   1.197 +PCK4BITS(0,0,0,0,0,0,6,0),  // 88 - 8f 
   1.198 +PCK4BITS(0,0,0,0,0,0,0,0),  // 90 - 97 
   1.199 +PCK4BITS(0,0,0,0,0,0,0,0),  // 98 - 9f 
   1.200 +PCK4BITS(0,3,4,4,4,4,4,4),  // a0 - a7 
   1.201 +PCK4BITS(5,5,1,1,1,1,1,1),  // a8 - af 
   1.202 +PCK4BITS(1,1,1,1,1,1,1,1),  // b0 - b7 
   1.203 +PCK4BITS(1,1,1,1,1,1,1,1),  // b8 - bf 
   1.204 +PCK4BITS(1,1,3,1,3,3,3,3),  // c0 - c7 
   1.205 +PCK4BITS(3,3,3,3,3,3,3,3),  // c8 - cf 
   1.206 +PCK4BITS(3,3,3,3,3,3,3,3),  // d0 - d7 
   1.207 +PCK4BITS(3,3,3,3,3,3,3,3),  // d8 - df 
   1.208 +PCK4BITS(3,3,3,3,3,3,3,3),  // e0 - e7 
   1.209 +PCK4BITS(3,3,3,3,3,3,3,3),  // e8 - ef 
   1.210 +PCK4BITS(3,3,3,3,3,3,3,3),  // f0 - f7 
   1.211 +PCK4BITS(3,3,3,3,3,3,3,0)   // f8 - ff 
   1.212 +};
   1.213 +
   1.214 +
   1.215 +static const uint32_t EUCTW_st [ 6] = {
   1.216 +PCK4BITS(eError,eError,eStart,     3,     3,     3,     4,eError),//00-07 
   1.217 +PCK4BITS(eError,eError,eError,eError,eError,eError,eItsMe,eItsMe),//08-0f 
   1.218 +PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError,eStart,eError),//10-17 
   1.219 +PCK4BITS(eStart,eStart,eStart,eError,eError,eError,eError,eError),//18-1f 
   1.220 +PCK4BITS(     5,eError,eError,eError,eStart,eError,eStart,eStart),//20-27 
   1.221 +PCK4BITS(eStart,eError,eStart,eStart,eStart,eStart,eStart,eStart) //28-2f 
   1.222 +};
   1.223 +
   1.224 +static const uint32_t EUCTWCharLenTable[] = {0, 0, 1, 2, 2, 2, 3};
   1.225 +
   1.226 +const SMModel EUCTWSMModel = {
   1.227 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCTW_cls },
   1.228 +   7,
   1.229 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCTW_st },
   1.230 +  CHAR_LEN_TABLE(EUCTWCharLenTable),
   1.231 +  "x-euc-tw",
   1.232 +};
   1.233 +
   1.234 +/* obsolete GB2312 by gb18030
   1.235 +static uint32_t GB2312_cls [ 256 / 8 ] = {
   1.236 +//PCK4BITS(0,1,1,1,1,1,1,1),  // 00 - 07 
   1.237 +PCK4BITS(1,1,1,1,1,1,1,1),  // 00 - 07 
   1.238 +PCK4BITS(1,1,1,1,1,1,0,0),  // 08 - 0f 
   1.239 +PCK4BITS(1,1,1,1,1,1,1,1),  // 10 - 17 
   1.240 +PCK4BITS(1,1,1,0,1,1,1,1),  // 18 - 1f 
   1.241 +PCK4BITS(1,1,1,1,1,1,1,1),  // 20 - 27 
   1.242 +PCK4BITS(1,1,1,1,1,1,1,1),  // 28 - 2f 
   1.243 +PCK4BITS(1,1,1,1,1,1,1,1),  // 30 - 37 
   1.244 +PCK4BITS(1,1,1,1,1,1,1,1),  // 38 - 3f 
   1.245 +PCK4BITS(1,1,1,1,1,1,1,1),  // 40 - 47 
   1.246 +PCK4BITS(1,1,1,1,1,1,1,1),  // 48 - 4f 
   1.247 +PCK4BITS(1,1,1,1,1,1,1,1),  // 50 - 57 
   1.248 +PCK4BITS(1,1,1,1,1,1,1,1),  // 58 - 5f 
   1.249 +PCK4BITS(1,1,1,1,1,1,1,1),  // 60 - 67 
   1.250 +PCK4BITS(1,1,1,1,1,1,1,1),  // 68 - 6f 
   1.251 +PCK4BITS(1,1,1,1,1,1,1,1),  // 70 - 77 
   1.252 +PCK4BITS(1,1,1,1,1,1,1,1),  // 78 - 7f 
   1.253 +PCK4BITS(1,0,0,0,0,0,0,0),  // 80 - 87 
   1.254 +PCK4BITS(0,0,0,0,0,0,0,0),  // 88 - 8f 
   1.255 +PCK4BITS(0,0,0,0,0,0,0,0),  // 90 - 97 
   1.256 +PCK4BITS(0,0,0,0,0,0,0,0),  // 98 - 9f 
   1.257 +PCK4BITS(0,2,2,2,2,2,2,2),  // a0 - a7 
   1.258 +PCK4BITS(2,2,3,3,3,3,3,3),  // a8 - af 
   1.259 +PCK4BITS(2,2,2,2,2,2,2,2),  // b0 - b7 
   1.260 +PCK4BITS(2,2,2,2,2,2,2,2),  // b8 - bf 
   1.261 +PCK4BITS(2,2,2,2,2,2,2,2),  // c0 - c7 
   1.262 +PCK4BITS(2,2,2,2,2,2,2,2),  // c8 - cf 
   1.263 +PCK4BITS(2,2,2,2,2,2,2,2),  // d0 - d7 
   1.264 +PCK4BITS(2,2,2,2,2,2,2,2),  // d8 - df 
   1.265 +PCK4BITS(2,2,2,2,2,2,2,2),  // e0 - e7 
   1.266 +PCK4BITS(2,2,2,2,2,2,2,2),  // e8 - ef 
   1.267 +PCK4BITS(2,2,2,2,2,2,2,2),  // f0 - f7 
   1.268 +PCK4BITS(2,2,2,2,2,2,2,0)   // f8 - ff 
   1.269 +};
   1.270 +
   1.271 +
   1.272 +static uint32_t GB2312_st [ 2] = {
   1.273 +PCK4BITS(eError,eStart,     3,eError,eError,eError,eError,eError),//00-07 
   1.274 +PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart,eStart) //08-0f 
   1.275 +};
   1.276 +
   1.277 +static const uint32_t GB2312CharLenTable[] = {0, 1, 2, 0};
   1.278 +
   1.279 +SMModel GB2312SMModel = {
   1.280 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB2312_cls },
   1.281 +   4,
   1.282 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB2312_st },
   1.283 +  CHAR_LEN_TABLE(GB2312CharLenTable),
   1.284 +  "GB2312",
   1.285 +};
   1.286 +*/
   1.287 +
   1.288 +// the following state machine data was created by perl script in 
   1.289 +// intl/chardet/tools. It should be the same as in PSM detector.
   1.290 +static const uint32_t GB18030_cls [ 256 / 8 ] = {
   1.291 +PCK4BITS(1,1,1,1,1,1,1,1),  // 00 - 07 
   1.292 +PCK4BITS(1,1,1,1,1,1,0,0),  // 08 - 0f 
   1.293 +PCK4BITS(1,1,1,1,1,1,1,1),  // 10 - 17 
   1.294 +PCK4BITS(1,1,1,0,1,1,1,1),  // 18 - 1f 
   1.295 +PCK4BITS(1,1,1,1,1,1,1,1),  // 20 - 27 
   1.296 +PCK4BITS(1,1,1,1,1,1,1,1),  // 28 - 2f 
   1.297 +PCK4BITS(3,3,3,3,3,3,3,3),  // 30 - 37 
   1.298 +PCK4BITS(3,3,1,1,1,1,1,1),  // 38 - 3f 
   1.299 +PCK4BITS(2,2,2,2,2,2,2,2),  // 40 - 47 
   1.300 +PCK4BITS(2,2,2,2,2,2,2,2),  // 48 - 4f 
   1.301 +PCK4BITS(2,2,2,2,2,2,2,2),  // 50 - 57 
   1.302 +PCK4BITS(2,2,2,2,2,2,2,2),  // 58 - 5f 
   1.303 +PCK4BITS(2,2,2,2,2,2,2,2),  // 60 - 67 
   1.304 +PCK4BITS(2,2,2,2,2,2,2,2),  // 68 - 6f 
   1.305 +PCK4BITS(2,2,2,2,2,2,2,2),  // 70 - 77 
   1.306 +PCK4BITS(2,2,2,2,2,2,2,4),  // 78 - 7f 
   1.307 +PCK4BITS(5,6,6,6,6,6,6,6),  // 80 - 87 
   1.308 +PCK4BITS(6,6,6,6,6,6,6,6),  // 88 - 8f 
   1.309 +PCK4BITS(6,6,6,6,6,6,6,6),  // 90 - 97 
   1.310 +PCK4BITS(6,6,6,6,6,6,6,6),  // 98 - 9f 
   1.311 +PCK4BITS(6,6,6,6,6,6,6,6),  // a0 - a7 
   1.312 +PCK4BITS(6,6,6,6,6,6,6,6),  // a8 - af 
   1.313 +PCK4BITS(6,6,6,6,6,6,6,6),  // b0 - b7 
   1.314 +PCK4BITS(6,6,6,6,6,6,6,6),  // b8 - bf 
   1.315 +PCK4BITS(6,6,6,6,6,6,6,6),  // c0 - c7 
   1.316 +PCK4BITS(6,6,6,6,6,6,6,6),  // c8 - cf 
   1.317 +PCK4BITS(6,6,6,6,6,6,6,6),  // d0 - d7 
   1.318 +PCK4BITS(6,6,6,6,6,6,6,6),  // d8 - df 
   1.319 +PCK4BITS(6,6,6,6,6,6,6,6),  // e0 - e7 
   1.320 +PCK4BITS(6,6,6,6,6,6,6,6),  // e8 - ef 
   1.321 +PCK4BITS(6,6,6,6,6,6,6,6),  // f0 - f7 
   1.322 +PCK4BITS(6,6,6,6,6,6,6,0)   // f8 - ff 
   1.323 +};
   1.324 +
   1.325 +
   1.326 +static const uint32_t GB18030_st [ 6] = {
   1.327 +PCK4BITS(eError,eStart,eStart,eStart,eStart,eStart,     3,eError),//00-07 
   1.328 +PCK4BITS(eError,eError,eError,eError,eError,eError,eItsMe,eItsMe),//08-0f 
   1.329 +PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart),//10-17 
   1.330 +PCK4BITS(     4,eError,eStart,eStart,eError,eError,eError,eError),//18-1f 
   1.331 +PCK4BITS(eError,eError,     5,eError,eError,eError,eItsMe,eError),//20-27 
   1.332 +PCK4BITS(eError,eError,eStart,eStart,eStart,eStart,eStart,eStart) //28-2f 
   1.333 +};
   1.334 +
   1.335 +// To be accurate, the length of class 6 can be either 2 or 4. 
   1.336 +// But it is not necessary to discriminate between the two since 
   1.337 +// it is used for frequency analysis only, and we are validing 
   1.338 +// each code range there as well. So it is safe to set it to be 
   1.339 +// 2 here. 
   1.340 +static const uint32_t GB18030CharLenTable[] = {0, 1, 1, 1, 1, 1, 2};
   1.341 +
   1.342 +const SMModel GB18030SMModel = {
   1.343 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB18030_cls },
   1.344 +   7,
   1.345 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB18030_st },
   1.346 +  CHAR_LEN_TABLE(GB18030CharLenTable),
   1.347 +  "GB18030",
   1.348 +};
   1.349 +
   1.350 +// sjis
   1.351 +
   1.352 +static const uint32_t SJIS_cls [ 256 / 8 ] = {
   1.353 +//PCK4BITS(0,1,1,1,1,1,1,1),  // 00 - 07 
   1.354 +PCK4BITS(1,1,1,1,1,1,1,1),  // 00 - 07 
   1.355 +PCK4BITS(1,1,1,1,1,1,0,0),  // 08 - 0f 
   1.356 +PCK4BITS(1,1,1,1,1,1,1,1),  // 10 - 17 
   1.357 +PCK4BITS(1,1,1,0,1,1,1,1),  // 18 - 1f 
   1.358 +PCK4BITS(1,1,1,1,1,1,1,1),  // 20 - 27 
   1.359 +PCK4BITS(1,1,1,1,1,1,1,1),  // 28 - 2f 
   1.360 +PCK4BITS(1,1,1,1,1,1,1,1),  // 30 - 37 
   1.361 +PCK4BITS(1,1,1,1,1,1,1,1),  // 38 - 3f 
   1.362 +PCK4BITS(2,2,2,2,2,2,2,2),  // 40 - 47 
   1.363 +PCK4BITS(2,2,2,2,2,2,2,2),  // 48 - 4f 
   1.364 +PCK4BITS(2,2,2,2,2,2,2,2),  // 50 - 57 
   1.365 +PCK4BITS(2,2,2,2,2,2,2,2),  // 58 - 5f 
   1.366 +PCK4BITS(2,2,2,2,2,2,2,2),  // 60 - 67 
   1.367 +PCK4BITS(2,2,2,2,2,2,2,2),  // 68 - 6f 
   1.368 +PCK4BITS(2,2,2,2,2,2,2,2),  // 70 - 77 
   1.369 +PCK4BITS(2,2,2,2,2,2,2,1),  // 78 - 7f 
   1.370 +PCK4BITS(3,3,3,3,3,3,3,3),  // 80 - 87 
   1.371 +PCK4BITS(3,3,3,3,3,3,3,3),  // 88 - 8f 
   1.372 +PCK4BITS(3,3,3,3,3,3,3,3),  // 90 - 97 
   1.373 +PCK4BITS(3,3,3,3,3,3,3,3),  // 98 - 9f 
   1.374 +//0xa0 is illegal in sjis encoding, but some pages does 
   1.375 +//contain such byte. We need to be more error forgiven.
   1.376 +PCK4BITS(2,2,2,2,2,2,2,2),  // a0 - a7     
   1.377 +PCK4BITS(2,2,2,2,2,2,2,2),  // a8 - af 
   1.378 +PCK4BITS(2,2,2,2,2,2,2,2),  // b0 - b7 
   1.379 +PCK4BITS(2,2,2,2,2,2,2,2),  // b8 - bf 
   1.380 +PCK4BITS(2,2,2,2,2,2,2,2),  // c0 - c7 
   1.381 +PCK4BITS(2,2,2,2,2,2,2,2),  // c8 - cf 
   1.382 +PCK4BITS(2,2,2,2,2,2,2,2),  // d0 - d7 
   1.383 +PCK4BITS(2,2,2,2,2,2,2,2),  // d8 - df 
   1.384 +PCK4BITS(3,3,3,3,3,3,3,3),  // e0 - e7 
   1.385 +PCK4BITS(3,3,3,3,3,4,4,4),  // e8 - ef 
   1.386 +PCK4BITS(4,4,4,4,4,4,4,4),  // f0 - f7 
   1.387 +PCK4BITS(4,4,4,4,4,0,0,0)   // f8 - ff 
   1.388 +};
   1.389 +
   1.390 +
   1.391 +static const uint32_t SJIS_st [ 3] = {
   1.392 +PCK4BITS(eError,eStart,eStart,     3,eError,eError,eError,eError),//00-07 
   1.393 +PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f 
   1.394 +PCK4BITS(eItsMe,eItsMe,eError,eError,eStart,eStart,eStart,eStart) //10-17 
   1.395 +};
   1.396 +
   1.397 +static const uint32_t SJISCharLenTable[] = {0, 1, 1, 2, 0, 0};
   1.398 +
   1.399 +const SMModel SJISSMModel = {
   1.400 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, SJIS_cls },
   1.401 +   6,
   1.402 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, SJIS_st },
   1.403 +  CHAR_LEN_TABLE(SJISCharLenTable),
   1.404 +  "Shift_JIS",
   1.405 +};
   1.406 +
   1.407 +
   1.408 +static const uint32_t UTF8_cls [ 256 / 8 ] = {
   1.409 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 00 - 07
   1.410 +PCK4BITS( 1, 1, 1, 1, 1, 1, 0, 0),  // 08 - 0f
   1.411 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 10 - 17
   1.412 +PCK4BITS( 1, 1, 1, 0, 1, 1, 1, 1),  // 18 - 1f
   1.413 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 20 - 27
   1.414 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 28 - 2f
   1.415 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 30 - 37
   1.416 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 38 - 3f
   1.417 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 40 - 47
   1.418 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 48 - 4f
   1.419 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 50 - 57
   1.420 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 58 - 5f
   1.421 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 60 - 67
   1.422 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 68 - 6f
   1.423 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 70 - 77
   1.424 +PCK4BITS( 1, 1, 1, 1, 1, 1, 1, 1),  // 78 - 7f
   1.425 +PCK4BITS( 2, 2, 2, 2, 2, 2, 2, 2),  // 80 - 87
   1.426 +PCK4BITS( 2, 2, 2, 2, 2, 2, 2, 2),  // 88 - 8f
   1.427 +PCK4BITS( 3, 3, 3, 3, 3, 3, 3, 3),  // 90 - 97
   1.428 +PCK4BITS( 3, 3, 3, 3, 3, 3, 3, 3),  // 98 - 9f
   1.429 +PCK4BITS( 4, 4, 4, 4, 4, 4, 4, 4),  // a0 - a7
   1.430 +PCK4BITS( 4, 4, 4, 4, 4, 4, 4, 4),  // a8 - af
   1.431 +PCK4BITS( 4, 4, 4, 4, 4, 4, 4, 4),  // b0 - b7
   1.432 +PCK4BITS( 4, 4, 4, 4, 4, 4, 4, 4),  // b8 - bf
   1.433 +PCK4BITS( 0, 0, 5, 5, 5, 5, 5, 5),  // c0 - c7
   1.434 +PCK4BITS( 5, 5, 5, 5, 5, 5, 5, 5),  // c8 - cf
   1.435 +PCK4BITS( 5, 5, 5, 5, 5, 5, 5, 5),  // d0 - d7
   1.436 +PCK4BITS( 5, 5, 5, 5, 5, 5, 5, 5),  // d8 - df
   1.437 +PCK4BITS( 6, 7, 7, 7, 7, 7, 7, 7),  // e0 - e7
   1.438 +PCK4BITS( 7, 7, 7, 7, 7, 8, 7, 7),  // e8 - ef
   1.439 +PCK4BITS( 9,10,10,10,11, 0, 0, 0),  // f0 - f7
   1.440 +PCK4BITS( 0, 0, 0, 0, 0, 0, 0, 0)   // f8 - ff
   1.441 +};
   1.442 +
   1.443 +
   1.444 +static const uint32_t UTF8_st [ 15] = {
   1.445 +PCK4BITS(eError,eStart,eError,eError,eError,     3,     4,     5),  // 00 - 07
   1.446 +PCK4BITS(     6,     7,     8,     9,eError,eError,eError,eError),  // 08 - 0f
   1.447 +PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),  // 10 - 17
   1.448 +PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe),  // 18 - 1f
   1.449 +PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart,eStart),  // 20 - 27
   1.450 +PCK4BITS(eStart,eError,eError,eError,eError,eError,eError,eError),  // 28 - 2f
   1.451 +PCK4BITS(eError,eError,eError,eError,     3,eError,eError,eError),  // 30 - 37
   1.452 +PCK4BITS(eError,eError,eError,eError,eError,eError,     3,     3),  // 38 - 3f
   1.453 +PCK4BITS(     3,eError,eError,eError,eError,eError,eError,eError),  // 40 - 47
   1.454 +PCK4BITS(eError,eError,     3,     3,eError,eError,eError,eError),  // 48 - 4f
   1.455 +PCK4BITS(eError,eError,eError,eError,eError,eError,     5,     5),  // 50 - 57
   1.456 +PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),  // 58 - 5f
   1.457 +PCK4BITS(eError,eError,     5,     5,     5,eError,eError,eError),  // 60 - 67
   1.458 +PCK4BITS(eError,eError,eError,eError,eError,eError,     5,eError),  // 68 - 6f
   1.459 +PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError)   // 70 - 77
   1.460 +};
   1.461 +
   1.462 +static const uint32_t UTF8CharLenTable[] = {0, 1, 0, 0, 0, 2, 3, 3, 3, 4, 4, 4};
   1.463 +
   1.464 +const SMModel UTF8SMModel = {
   1.465 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UTF8_cls },
   1.466 +   12,
   1.467 +  {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UTF8_st },
   1.468 +  CHAR_LEN_TABLE(UTF8CharLenTable),
   1.469 +  "UTF-8",
   1.470 +};

mercurial