KDECore
nsMBCSSM.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 00002 /* -*- C++ -*- 00003 * Copyright (C) 1998 <developer@mozilla.org> 00004 * 00005 * 00006 * Permission is hereby granted, free of charge, to any person obtaining 00007 * a copy of this software and associated documentation files (the 00008 * "Software"), to deal in the Software without restriction, including 00009 * without limitation the rights to use, copy, modify, merge, publish, 00010 * distribute, sublicense, and/or sell copies of the Software, and to 00011 * permit persons to whom the Software is furnished to do so, subject to 00012 * the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included 00015 * in all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00018 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00019 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00020 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00021 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00022 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00023 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00024 */ 00025 00026 #include "nsCodingStateMachine.h" 00027 00028 /* 00029 Modification from frank tang's original work: 00030 . 0x00 is allowed as a legal character. Since some web pages contains this char in 00031 text stream. 00032 */ 00033 00034 // BIG5 00035 00036 namespace kencodingprober { 00037 static unsigned int BIG5_cls [ 256 / 8 ] = { 00038 //PCK4BITS(0,1,1,1,1,1,1,1), // 00 - 07 00039 PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07 //allow 0x00 as legal value 00040 PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f 00041 PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17 00042 PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f 00043 PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27 00044 PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f 00045 PCK4BITS(1,1,1,1,1,1,1,1), // 30 - 37 00046 PCK4BITS(1,1,1,1,1,1,1,1), // 38 - 3f 00047 PCK4BITS(2,2,2,2,2,2,2,2), // 40 - 47 00048 PCK4BITS(2,2,2,2,2,2,2,2), // 48 - 4f 00049 PCK4BITS(2,2,2,2,2,2,2,2), // 50 - 57 00050 PCK4BITS(2,2,2,2,2,2,2,2), // 58 - 5f 00051 PCK4BITS(2,2,2,2,2,2,2,2), // 60 - 67 00052 PCK4BITS(2,2,2,2,2,2,2,2), // 68 - 6f 00053 PCK4BITS(2,2,2,2,2,2,2,2), // 70 - 77 00054 PCK4BITS(2,2,2,2,2,2,2,1), // 78 - 7f 00055 PCK4BITS(4,4,4,4,4,4,4,4), // 80 - 87 00056 PCK4BITS(4,4,4,4,4,4,4,4), // 88 - 8f 00057 PCK4BITS(4,4,4,4,4,4,4,4), // 90 - 97 00058 PCK4BITS(4,4,4,4,4,4,4,4), // 98 - 9f 00059 PCK4BITS(4,3,3,3,3,3,3,3), // a0 - a7 00060 PCK4BITS(3,3,3,3,3,3,3,3), // a8 - af 00061 PCK4BITS(3,3,3,3,3,3,3,3), // b0 - b7 00062 PCK4BITS(3,3,3,3,3,3,3,3), // b8 - bf 00063 PCK4BITS(3,3,3,3,3,3,3,3), // c0 - c7 00064 PCK4BITS(3,3,3,3,3,3,3,3), // c8 - cf 00065 PCK4BITS(3,3,3,3,3,3,3,3), // d0 - d7 00066 PCK4BITS(3,3,3,3,3,3,3,3), // d8 - df 00067 PCK4BITS(3,3,3,3,3,3,3,3), // e0 - e7 00068 PCK4BITS(3,3,3,3,3,3,3,3), // e8 - ef 00069 PCK4BITS(3,3,3,3,3,3,3,3), // f0 - f7 00070 PCK4BITS(3,3,3,3,3,3,3,0) // f8 - ff 00071 }; 00072 00073 00074 static unsigned int BIG5_st [ 3] = { 00075 PCK4BITS(eError,eStart,eStart, 3,eError,eError,eError,eError),//00-07 00076 PCK4BITS(eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError),//08-0f 00077 PCK4BITS(eError,eStart,eStart,eStart,eStart,eStart,eStart,eStart) //10-17 00078 }; 00079 00080 static const unsigned int Big5CharLenTable[] = {0, 1, 1, 2, 0}; 00081 00082 SMModel Big5SMModel = { 00083 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, BIG5_cls }, 00084 5, 00085 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, BIG5_st }, 00086 Big5CharLenTable, 00087 "Big5", 00088 }; 00089 00090 static unsigned int EUCJP_cls [ 256 / 8 ] = { 00091 //PCK4BITS(5,4,4,4,4,4,4,4), // 00 - 07 00092 PCK4BITS(4,4,4,4,4,4,4,4), // 00 - 07 00093 PCK4BITS(4,4,4,4,4,4,5,5), // 08 - 0f 00094 PCK4BITS(4,4,4,4,4,4,4,4), // 10 - 17 00095 PCK4BITS(4,4,4,5,4,4,4,4), // 18 - 1f 00096 PCK4BITS(4,4,4,4,4,4,4,4), // 20 - 27 00097 PCK4BITS(4,4,4,4,4,4,4,4), // 28 - 2f 00098 PCK4BITS(4,4,4,4,4,4,4,4), // 30 - 37 00099 PCK4BITS(4,4,4,4,4,4,4,4), // 38 - 3f 00100 PCK4BITS(4,4,4,4,4,4,4,4), // 40 - 47 00101 PCK4BITS(4,4,4,4,4,4,4,4), // 48 - 4f 00102 PCK4BITS(4,4,4,4,4,4,4,4), // 50 - 57 00103 PCK4BITS(4,4,4,4,4,4,4,4), // 58 - 5f 00104 PCK4BITS(4,4,4,4,4,4,4,4), // 60 - 67 00105 PCK4BITS(4,4,4,4,4,4,4,4), // 68 - 6f 00106 PCK4BITS(4,4,4,4,4,4,4,4), // 70 - 77 00107 PCK4BITS(4,4,4,4,4,4,4,4), // 78 - 7f 00108 PCK4BITS(5,5,5,5,5,5,5,5), // 80 - 87 00109 PCK4BITS(5,5,5,5,5,5,1,3), // 88 - 8f 00110 PCK4BITS(5,5,5,5,5,5,5,5), // 90 - 97 00111 PCK4BITS(5,5,5,5,5,5,5,5), // 98 - 9f 00112 PCK4BITS(5,2,2,2,2,2,2,2), // a0 - a7 00113 PCK4BITS(2,2,2,2,2,2,2,2), // a8 - af 00114 PCK4BITS(2,2,2,2,2,2,2,2), // b0 - b7 00115 PCK4BITS(2,2,2,2,2,2,2,2), // b8 - bf 00116 PCK4BITS(2,2,2,2,2,2,2,2), // c0 - c7 00117 PCK4BITS(2,2,2,2,2,2,2,2), // c8 - cf 00118 PCK4BITS(2,2,2,2,2,2,2,2), // d0 - d7 00119 PCK4BITS(2,2,2,2,2,2,2,2), // d8 - df 00120 PCK4BITS(0,0,0,0,0,0,0,0), // e0 - e7 00121 PCK4BITS(0,0,0,0,0,0,0,0), // e8 - ef 00122 PCK4BITS(0,0,0,0,0,0,0,0), // f0 - f7 00123 PCK4BITS(0,0,0,0,0,0,0,5) // f8 - ff 00124 }; 00125 00126 00127 static unsigned int EUCJP_st [ 5] = { 00128 PCK4BITS( 3, 4, 3, 5,eStart,eError,eError,eError),//00-07 00129 PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f 00130 PCK4BITS(eItsMe,eItsMe,eStart,eError,eStart,eError,eError,eError),//10-17 00131 PCK4BITS(eError,eError,eStart,eError,eError,eError, 3,eError),//18-1f 00132 PCK4BITS( 3,eError,eError,eError,eStart,eStart,eStart,eStart) //20-27 00133 }; 00134 00135 static const unsigned int EUCJPCharLenTable[] = {2, 2, 2, 3, 1, 0}; 00136 00137 SMModel EUCJPSMModel = { 00138 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCJP_cls }, 00139 6, 00140 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCJP_st }, 00141 EUCJPCharLenTable, 00142 "EUC-JP", 00143 }; 00144 00145 static unsigned int EUCKR_cls [ 256 / 8 ] = { 00146 //PCK4BITS(0,1,1,1,1,1,1,1), // 00 - 07 00147 PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07 00148 PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f 00149 PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17 00150 PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f 00151 PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27 00152 PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f 00153 PCK4BITS(1,1,1,1,1,1,1,1), // 30 - 37 00154 PCK4BITS(1,1,1,1,1,1,1,1), // 38 - 3f 00155 PCK4BITS(1,1,1,1,1,1,1,1), // 40 - 47 00156 PCK4BITS(1,1,1,1,1,1,1,1), // 48 - 4f 00157 PCK4BITS(1,1,1,1,1,1,1,1), // 50 - 57 00158 PCK4BITS(1,1,1,1,1,1,1,1), // 58 - 5f 00159 PCK4BITS(1,1,1,1,1,1,1,1), // 60 - 67 00160 PCK4BITS(1,1,1,1,1,1,1,1), // 68 - 6f 00161 PCK4BITS(1,1,1,1,1,1,1,1), // 70 - 77 00162 PCK4BITS(1,1,1,1,1,1,1,1), // 78 - 7f 00163 PCK4BITS(0,0,0,0,0,0,0,0), // 80 - 87 00164 PCK4BITS(0,0,0,0,0,0,0,0), // 88 - 8f 00165 PCK4BITS(0,0,0,0,0,0,0,0), // 90 - 97 00166 PCK4BITS(0,0,0,0,0,0,0,0), // 98 - 9f 00167 PCK4BITS(0,2,2,2,2,2,2,2), // a0 - a7 00168 PCK4BITS(2,2,2,2,2,3,3,3), // a8 - af 00169 PCK4BITS(2,2,2,2,2,2,2,2), // b0 - b7 00170 PCK4BITS(2,2,2,2,2,2,2,2), // b8 - bf 00171 PCK4BITS(2,2,2,2,2,2,2,2), // c0 - c7 00172 PCK4BITS(2,3,2,2,2,2,2,2), // c8 - cf 00173 PCK4BITS(2,2,2,2,2,2,2,2), // d0 - d7 00174 PCK4BITS(2,2,2,2,2,2,2,2), // d8 - df 00175 PCK4BITS(2,2,2,2,2,2,2,2), // e0 - e7 00176 PCK4BITS(2,2,2,2,2,2,2,2), // e8 - ef 00177 PCK4BITS(2,2,2,2,2,2,2,2), // f0 - f7 00178 PCK4BITS(2,2,2,2,2,2,2,0) // f8 - ff 00179 }; 00180 00181 00182 static unsigned int EUCKR_st [ 2] = { 00183 PCK4BITS(eError,eStart, 3,eError,eError,eError,eError,eError),//00-07 00184 PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart,eStart) //08-0f 00185 }; 00186 00187 static const unsigned int EUCKRCharLenTable[] = {0, 1, 2, 0}; 00188 00189 SMModel EUCKRSMModel = { 00190 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCKR_cls }, 00191 4, 00192 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCKR_st }, 00193 EUCKRCharLenTable, 00194 "EUC-KR", 00195 }; 00196 00197 static unsigned int EUCTW_cls [ 256 / 8 ] = { 00198 //PCK4BITS(0,2,2,2,2,2,2,2), // 00 - 07 00199 PCK4BITS(2,2,2,2,2,2,2,2), // 00 - 07 00200 PCK4BITS(2,2,2,2,2,2,0,0), // 08 - 0f 00201 PCK4BITS(2,2,2,2,2,2,2,2), // 10 - 17 00202 PCK4BITS(2,2,2,0,2,2,2,2), // 18 - 1f 00203 PCK4BITS(2,2,2,2,2,2,2,2), // 20 - 27 00204 PCK4BITS(2,2,2,2,2,2,2,2), // 28 - 2f 00205 PCK4BITS(2,2,2,2,2,2,2,2), // 30 - 37 00206 PCK4BITS(2,2,2,2,2,2,2,2), // 38 - 3f 00207 PCK4BITS(2,2,2,2,2,2,2,2), // 40 - 47 00208 PCK4BITS(2,2,2,2,2,2,2,2), // 48 - 4f 00209 PCK4BITS(2,2,2,2,2,2,2,2), // 50 - 57 00210 PCK4BITS(2,2,2,2,2,2,2,2), // 58 - 5f 00211 PCK4BITS(2,2,2,2,2,2,2,2), // 60 - 67 00212 PCK4BITS(2,2,2,2,2,2,2,2), // 68 - 6f 00213 PCK4BITS(2,2,2,2,2,2,2,2), // 70 - 77 00214 PCK4BITS(2,2,2,2,2,2,2,2), // 78 - 7f 00215 PCK4BITS(0,0,0,0,0,0,0,0), // 80 - 87 00216 PCK4BITS(0,0,0,0,0,0,6,0), // 88 - 8f 00217 PCK4BITS(0,0,0,0,0,0,0,0), // 90 - 97 00218 PCK4BITS(0,0,0,0,0,0,0,0), // 98 - 9f 00219 PCK4BITS(0,3,4,4,4,4,4,4), // a0 - a7 00220 PCK4BITS(5,5,1,1,1,1,1,1), // a8 - af 00221 PCK4BITS(1,1,1,1,1,1,1,1), // b0 - b7 00222 PCK4BITS(1,1,1,1,1,1,1,1), // b8 - bf 00223 PCK4BITS(1,1,3,1,3,3,3,3), // c0 - c7 00224 PCK4BITS(3,3,3,3,3,3,3,3), // c8 - cf 00225 PCK4BITS(3,3,3,3,3,3,3,3), // d0 - d7 00226 PCK4BITS(3,3,3,3,3,3,3,3), // d8 - df 00227 PCK4BITS(3,3,3,3,3,3,3,3), // e0 - e7 00228 PCK4BITS(3,3,3,3,3,3,3,3), // e8 - ef 00229 PCK4BITS(3,3,3,3,3,3,3,3), // f0 - f7 00230 PCK4BITS(3,3,3,3,3,3,3,0) // f8 - ff 00231 }; 00232 00233 00234 static unsigned int EUCTW_st [ 6] = { 00235 PCK4BITS(eError,eError,eStart, 3, 3, 3, 4,eError),//00-07 00236 PCK4BITS(eError,eError,eError,eError,eError,eError,eItsMe,eItsMe),//08-0f 00237 PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError,eStart,eError),//10-17 00238 PCK4BITS(eStart,eStart,eStart,eError,eError,eError,eError,eError),//18-1f 00239 PCK4BITS( 5,eError,eError,eError,eStart,eError,eStart,eStart),//20-27 00240 PCK4BITS(eStart,eError,eStart,eStart,eStart,eStart,eStart,eStart) //28-2f 00241 }; 00242 00243 static const unsigned int EUCTWCharLenTable[] = {0, 0, 1, 2, 2, 2, 3}; 00244 00245 SMModel EUCTWSMModel = { 00246 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCTW_cls }, 00247 7, 00248 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCTW_st }, 00249 EUCTWCharLenTable, 00250 "x-euc-tw", 00251 }; 00252 00253 /* obsolete GB2312 by gb18030 00254 static unsigned int GB2312_cls [ 256 / 8 ] = { 00255 //PCK4BITS(0,1,1,1,1,1,1,1), // 00 - 07 00256 PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07 00257 PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f 00258 PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17 00259 PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f 00260 PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27 00261 PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f 00262 PCK4BITS(1,1,1,1,1,1,1,1), // 30 - 37 00263 PCK4BITS(1,1,1,1,1,1,1,1), // 38 - 3f 00264 PCK4BITS(1,1,1,1,1,1,1,1), // 40 - 47 00265 PCK4BITS(1,1,1,1,1,1,1,1), // 48 - 4f 00266 PCK4BITS(1,1,1,1,1,1,1,1), // 50 - 57 00267 PCK4BITS(1,1,1,1,1,1,1,1), // 58 - 5f 00268 PCK4BITS(1,1,1,1,1,1,1,1), // 60 - 67 00269 PCK4BITS(1,1,1,1,1,1,1,1), // 68 - 6f 00270 PCK4BITS(1,1,1,1,1,1,1,1), // 70 - 77 00271 PCK4BITS(1,1,1,1,1,1,1,1), // 78 - 7f 00272 PCK4BITS(1,0,0,0,0,0,0,0), // 80 - 87 00273 PCK4BITS(0,0,0,0,0,0,0,0), // 88 - 8f 00274 PCK4BITS(0,0,0,0,0,0,0,0), // 90 - 97 00275 PCK4BITS(0,0,0,0,0,0,0,0), // 98 - 9f 00276 PCK4BITS(0,2,2,2,2,2,2,2), // a0 - a7 00277 PCK4BITS(2,2,3,3,3,3,3,3), // a8 - af 00278 PCK4BITS(2,2,2,2,2,2,2,2), // b0 - b7 00279 PCK4BITS(2,2,2,2,2,2,2,2), // b8 - bf 00280 PCK4BITS(2,2,2,2,2,2,2,2), // c0 - c7 00281 PCK4BITS(2,2,2,2,2,2,2,2), // c8 - cf 00282 PCK4BITS(2,2,2,2,2,2,2,2), // d0 - d7 00283 PCK4BITS(2,2,2,2,2,2,2,2), // d8 - df 00284 PCK4BITS(2,2,2,2,2,2,2,2), // e0 - e7 00285 PCK4BITS(2,2,2,2,2,2,2,2), // e8 - ef 00286 PCK4BITS(2,2,2,2,2,2,2,2), // f0 - f7 00287 PCK4BITS(2,2,2,2,2,2,2,0) // f8 - ff 00288 }; 00289 00290 00291 static unsigned int GB2312_st [ 2] = { 00292 PCK4BITS(eError,eStart, 3,eError,eError,eError,eError,eError),//00-07 00293 PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart,eStart) //08-0f 00294 }; 00295 00296 static const unsigned int GB2312CharLenTable[] = {0, 1, 2, 0}; 00297 00298 SMModel GB2312SMModel = { 00299 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB2312_cls }, 00300 4, 00301 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB2312_st }, 00302 GB2312CharLenTable, 00303 "GB2312", 00304 }; 00305 */ 00306 00307 // the following state machine data was created by perl script in 00308 // intl/chardet/tools. It should be the same as in PSM detector. 00309 static unsigned int GB18030_cls [ 256 / 8 ] = { 00310 PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07 00311 PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f 00312 PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17 00313 PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f 00314 PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27 00315 PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f 00316 PCK4BITS(3,3,3,3,3,3,3,3), // 30 - 37 00317 PCK4BITS(3,3,1,1,1,1,1,1), // 38 - 3f 00318 PCK4BITS(2,2,2,2,2,2,2,2), // 40 - 47 00319 PCK4BITS(2,2,2,2,2,2,2,2), // 48 - 4f 00320 PCK4BITS(2,2,2,2,2,2,2,2), // 50 - 57 00321 PCK4BITS(2,2,2,2,2,2,2,2), // 58 - 5f 00322 PCK4BITS(2,2,2,2,2,2,2,2), // 60 - 67 00323 PCK4BITS(2,2,2,2,2,2,2,2), // 68 - 6f 00324 PCK4BITS(2,2,2,2,2,2,2,2), // 70 - 77 00325 PCK4BITS(2,2,2,2,2,2,2,4), // 78 - 7f 00326 PCK4BITS(5,6,6,6,6,6,6,6), // 80 - 87 00327 PCK4BITS(6,6,6,6,6,6,6,6), // 88 - 8f 00328 PCK4BITS(6,6,6,6,6,6,6,6), // 90 - 97 00329 PCK4BITS(6,6,6,6,6,6,6,6), // 98 - 9f 00330 PCK4BITS(6,6,6,6,6,6,6,6), // a0 - a7 00331 PCK4BITS(6,6,6,6,6,6,6,6), // a8 - af 00332 PCK4BITS(6,6,6,6,6,6,6,6), // b0 - b7 00333 PCK4BITS(6,6,6,6,6,6,6,6), // b8 - bf 00334 PCK4BITS(6,6,6,6,6,6,6,6), // c0 - c7 00335 PCK4BITS(6,6,6,6,6,6,6,6), // c8 - cf 00336 PCK4BITS(6,6,6,6,6,6,6,6), // d0 - d7 00337 PCK4BITS(6,6,6,6,6,6,6,6), // d8 - df 00338 PCK4BITS(6,6,6,6,6,6,6,6), // e0 - e7 00339 PCK4BITS(6,6,6,6,6,6,6,6), // e8 - ef 00340 PCK4BITS(6,6,6,6,6,6,6,6), // f0 - f7 00341 PCK4BITS(6,6,6,6,6,6,6,0) // f8 - ff 00342 }; 00343 00344 00345 static unsigned int GB18030_st [ 6] = { 00346 PCK4BITS(eError,eStart,eStart,eStart,eStart,eStart, 3,eError),//00-07 00347 PCK4BITS(eError,eError,eError,eError,eError,eError,eItsMe,eItsMe),//08-0f 00348 PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,eStart),//10-17 00349 PCK4BITS( 4,eError,eStart,eStart,eError,eError,eError,eError),//18-1f 00350 PCK4BITS(eError,eError, 5,eError,eError,eError,eItsMe,eError),//20-27 00351 PCK4BITS(eError,eError,eStart,eStart,eStart,eStart,eStart,eStart) //28-2f 00352 }; 00353 00354 // To be accurate, the length of class 6 can be either 2 or 4. 00355 // But it is not necessary to discriminate between the two since 00356 // it is used for frequency analysis only, and we are validing 00357 // each code range there as well. So it is safe to set it to be 00358 // 2 here. 00359 static const unsigned int GB18030CharLenTable[] = {0, 1, 1, 1, 1, 1, 2}; 00360 00361 SMModel GB18030SMModel = { 00362 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB18030_cls }, 00363 7, 00364 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, GB18030_st }, 00365 GB18030CharLenTable, 00366 "GB18030", 00367 }; 00368 00369 // sjis 00370 00371 static unsigned int SJIS_cls [ 256 / 8 ] = { 00372 //PCK4BITS(0,1,1,1,1,1,1,1), // 00 - 07 00373 PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07 00374 PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f 00375 PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17 00376 PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f 00377 PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27 00378 PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f 00379 PCK4BITS(1,1,1,1,1,1,1,1), // 30 - 37 00380 PCK4BITS(1,1,1,1,1,1,1,1), // 38 - 3f 00381 PCK4BITS(2,2,2,2,2,2,2,2), // 40 - 47 00382 PCK4BITS(2,2,2,2,2,2,2,2), // 48 - 4f 00383 PCK4BITS(2,2,2,2,2,2,2,2), // 50 - 57 00384 PCK4BITS(2,2,2,2,2,2,2,2), // 58 - 5f 00385 PCK4BITS(2,2,2,2,2,2,2,2), // 60 - 67 00386 PCK4BITS(2,2,2,2,2,2,2,2), // 68 - 6f 00387 PCK4BITS(2,2,2,2,2,2,2,2), // 70 - 77 00388 PCK4BITS(2,2,2,2,2,2,2,1), // 78 - 7f 00389 PCK4BITS(3,3,3,3,3,3,3,3), // 80 - 87 00390 PCK4BITS(3,3,3,3,3,3,3,3), // 88 - 8f 00391 PCK4BITS(3,3,3,3,3,3,3,3), // 90 - 97 00392 PCK4BITS(3,3,3,3,3,3,3,3), // 98 - 9f 00393 //0xa0 is illegal in sjis encoding, but some pages does 00394 //contain such byte. We need to be more error forgiven. 00395 PCK4BITS(2,2,2,2,2,2,2,2), // a0 - a7 00396 PCK4BITS(2,2,2,2,2,2,2,2), // a8 - af 00397 PCK4BITS(2,2,2,2,2,2,2,2), // b0 - b7 00398 PCK4BITS(2,2,2,2,2,2,2,2), // b8 - bf 00399 PCK4BITS(2,2,2,2,2,2,2,2), // c0 - c7 00400 PCK4BITS(2,2,2,2,2,2,2,2), // c8 - cf 00401 PCK4BITS(2,2,2,2,2,2,2,2), // d0 - d7 00402 PCK4BITS(2,2,2,2,2,2,2,2), // d8 - df 00403 PCK4BITS(3,3,3,3,3,3,3,3), // e0 - e7 00404 PCK4BITS(3,3,3,3,3,4,4,4), // e8 - ef 00405 PCK4BITS(4,4,4,4,4,4,4,4), // f0 - f7 00406 PCK4BITS(4,4,4,4,4,0,0,0) // f8 - ff 00407 }; 00408 00409 00410 static unsigned int SJIS_st [ 3] = { 00411 PCK4BITS(eError,eStart,eStart, 3,eError,eError,eError,eError),//00-07 00412 PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f 00413 PCK4BITS(eItsMe,eItsMe,eError,eError,eStart,eStart,eStart,eStart) //10-17 00414 }; 00415 00416 static const unsigned int SJISCharLenTable[] = {0, 1, 1, 2, 0, 0}; 00417 00418 SMModel SJISSMModel = { 00419 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, SJIS_cls }, 00420 6, 00421 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, SJIS_st }, 00422 SJISCharLenTable, 00423 "Shift_JIS", 00424 }; 00425 00426 00427 static unsigned int UCS2BE_cls [ 256 / 8 ] = { 00428 PCK4BITS(0,0,0,0,0,0,0,0), // 00 - 07 00429 PCK4BITS(0,0,1,0,0,2,0,0), // 08 - 0f 00430 PCK4BITS(0,0,0,0,0,0,0,0), // 10 - 17 00431 PCK4BITS(0,0,0,3,0,0,0,0), // 18 - 1f 00432 PCK4BITS(0,0,0,0,0,0,0,0), // 20 - 27 00433 PCK4BITS(0,3,3,3,3,3,0,0), // 28 - 2f 00434 PCK4BITS(0,0,0,0,0,0,0,0), // 30 - 37 00435 PCK4BITS(0,0,0,0,0,0,0,0), // 38 - 3f 00436 PCK4BITS(0,0,0,0,0,0,0,0), // 40 - 47 00437 PCK4BITS(0,0,0,0,0,0,0,0), // 48 - 4f 00438 PCK4BITS(0,0,0,0,0,0,0,0), // 50 - 57 00439 PCK4BITS(0,0,0,0,0,0,0,0), // 58 - 5f 00440 PCK4BITS(0,0,0,0,0,0,0,0), // 60 - 67 00441 PCK4BITS(0,0,0,0,0,0,0,0), // 68 - 6f 00442 PCK4BITS(0,0,0,0,0,0,0,0), // 70 - 77 00443 PCK4BITS(0,0,0,0,0,0,0,0), // 78 - 7f 00444 PCK4BITS(0,0,0,0,0,0,0,0), // 80 - 87 00445 PCK4BITS(0,0,0,0,0,0,0,0), // 88 - 8f 00446 PCK4BITS(0,0,0,0,0,0,0,0), // 90 - 97 00447 PCK4BITS(0,0,0,0,0,0,0,0), // 98 - 9f 00448 PCK4BITS(0,0,0,0,0,0,0,0), // a0 - a7 00449 PCK4BITS(0,0,0,0,0,0,0,0), // a8 - af 00450 PCK4BITS(0,0,0,0,0,0,0,0), // b0 - b7 00451 PCK4BITS(0,0,0,0,0,0,0,0), // b8 - bf 00452 PCK4BITS(0,0,0,0,0,0,0,0), // c0 - c7 00453 PCK4BITS(0,0,0,0,0,0,0,0), // c8 - cf 00454 PCK4BITS(0,0,0,0,0,0,0,0), // d0 - d7 00455 PCK4BITS(0,0,0,0,0,0,0,0), // d8 - df 00456 PCK4BITS(0,0,0,0,0,0,0,0), // e0 - e7 00457 PCK4BITS(0,0,0,0,0,0,0,0), // e8 - ef 00458 PCK4BITS(0,0,0,0,0,0,0,0), // f0 - f7 00459 PCK4BITS(0,0,0,0,0,0,4,5) // f8 - ff 00460 }; 00461 00462 00463 static unsigned int UCS2BE_st [ 7] = { 00464 PCK4BITS( 5, 7, 7,eError, 4, 3,eError,eError),//00-07 00465 PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f 00466 PCK4BITS(eItsMe,eItsMe, 6, 6, 6, 6,eError,eError),//10-17 00467 PCK4BITS( 6, 6, 6, 6, 6,eItsMe, 6, 6),//18-1f 00468 PCK4BITS( 6, 6, 6, 6, 5, 7, 7,eError),//20-27 00469 PCK4BITS( 5, 8, 6, 6,eError, 6, 6, 6),//28-2f 00470 PCK4BITS( 6, 6, 6, 6,eError,eError,eStart,eStart) //30-37 00471 }; 00472 00473 static const unsigned int UCS2BECharLenTable[] = {2, 2, 2, 0, 2, 2}; 00474 00475 SMModel UCS2BESMModel = { 00476 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UCS2BE_cls }, 00477 6, 00478 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UCS2BE_st }, 00479 UCS2BECharLenTable, 00480 "UTF-16BE", 00481 }; 00482 00483 static unsigned int UCS2LE_cls [ 256 / 8 ] = { 00484 PCK4BITS(0,0,0,0,0,0,0,0), // 00 - 07 00485 PCK4BITS(0,0,1,0,0,2,0,0), // 08 - 0f 00486 PCK4BITS(0,0,0,0,0,0,0,0), // 10 - 17 00487 PCK4BITS(0,0,0,3,0,0,0,0), // 18 - 1f 00488 PCK4BITS(0,0,0,0,0,0,0,0), // 20 - 27 00489 PCK4BITS(0,3,3,3,3,3,0,0), // 28 - 2f 00490 PCK4BITS(0,0,0,0,0,0,0,0), // 30 - 37 00491 PCK4BITS(0,0,0,0,0,0,0,0), // 38 - 3f 00492 PCK4BITS(0,0,0,0,0,0,0,0), // 40 - 47 00493 PCK4BITS(0,0,0,0,0,0,0,0), // 48 - 4f 00494 PCK4BITS(0,0,0,0,0,0,0,0), // 50 - 57 00495 PCK4BITS(0,0,0,0,0,0,0,0), // 58 - 5f 00496 PCK4BITS(0,0,0,0,0,0,0,0), // 60 - 67 00497 PCK4BITS(0,0,0,0,0,0,0,0), // 68 - 6f 00498 PCK4BITS(0,0,0,0,0,0,0,0), // 70 - 77 00499 PCK4BITS(0,0,0,0,0,0,0,0), // 78 - 7f 00500 PCK4BITS(0,0,0,0,0,0,0,0), // 80 - 87 00501 PCK4BITS(0,0,0,0,0,0,0,0), // 88 - 8f 00502 PCK4BITS(0,0,0,0,0,0,0,0), // 90 - 97 00503 PCK4BITS(0,0,0,0,0,0,0,0), // 98 - 9f 00504 PCK4BITS(0,0,0,0,0,0,0,0), // a0 - a7 00505 PCK4BITS(0,0,0,0,0,0,0,0), // a8 - af 00506 PCK4BITS(0,0,0,0,0,0,0,0), // b0 - b7 00507 PCK4BITS(0,0,0,0,0,0,0,0), // b8 - bf 00508 PCK4BITS(0,0,0,0,0,0,0,0), // c0 - c7 00509 PCK4BITS(0,0,0,0,0,0,0,0), // c8 - cf 00510 PCK4BITS(0,0,0,0,0,0,0,0), // d0 - d7 00511 PCK4BITS(0,0,0,0,0,0,0,0), // d8 - df 00512 PCK4BITS(0,0,0,0,0,0,0,0), // e0 - e7 00513 PCK4BITS(0,0,0,0,0,0,0,0), // e8 - ef 00514 PCK4BITS(0,0,0,0,0,0,0,0), // f0 - f7 00515 PCK4BITS(0,0,0,0,0,0,4,5) // f8 - ff 00516 }; 00517 00518 00519 static unsigned int UCS2LE_st [ 7] = { 00520 PCK4BITS( 6, 6, 7, 6, 4, 3,eError,eError),//00-07 00521 PCK4BITS(eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe),//08-0f 00522 PCK4BITS(eItsMe,eItsMe, 5, 5, 5,eError,eItsMe,eError),//10-17 00523 PCK4BITS( 5, 5, 5,eError, 5,eError, 6, 6),//18-1f 00524 PCK4BITS( 7, 6, 8, 8, 5, 5, 5,eError),//20-27 00525 PCK4BITS( 5, 5, 5,eError,eError,eError, 5, 5),//28-2f 00526 PCK4BITS( 5, 5, 5,eError, 5,eError,eStart,eStart) //30-37 00527 }; 00528 00529 static const unsigned int UCS2LECharLenTable[] = {2, 2, 2, 2, 2, 2}; 00530 00531 SMModel UCS2LESMModel = { 00532 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UCS2LE_cls }, 00533 6, 00534 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UCS2LE_st }, 00535 UCS2LECharLenTable, 00536 "UTF-16LE", 00537 }; 00538 00539 00540 static unsigned int UTF8_cls [ 256 / 8 ] = { 00541 //PCK4BITS(0,1,1,1,1,1,1,1), // 00 - 07 00542 PCK4BITS(1,1,1,1,1,1,1,1), // 00 - 07 //allow 0x00 as a legal value 00543 PCK4BITS(1,1,1,1,1,1,0,0), // 08 - 0f 00544 PCK4BITS(1,1,1,1,1,1,1,1), // 10 - 17 00545 PCK4BITS(1,1,1,0,1,1,1,1), // 18 - 1f 00546 PCK4BITS(1,1,1,1,1,1,1,1), // 20 - 27 00547 PCK4BITS(1,1,1,1,1,1,1,1), // 28 - 2f 00548 PCK4BITS(1,1,1,1,1,1,1,1), // 30 - 37 00549 PCK4BITS(1,1,1,1,1,1,1,1), // 38 - 3f 00550 PCK4BITS(1,1,1,1,1,1,1,1), // 40 - 47 00551 PCK4BITS(1,1,1,1,1,1,1,1), // 48 - 4f 00552 PCK4BITS(1,1,1,1,1,1,1,1), // 50 - 57 00553 PCK4BITS(1,1,1,1,1,1,1,1), // 58 - 5f 00554 PCK4BITS(1,1,1,1,1,1,1,1), // 60 - 67 00555 PCK4BITS(1,1,1,1,1,1,1,1), // 68 - 6f 00556 PCK4BITS(1,1,1,1,1,1,1,1), // 70 - 77 00557 PCK4BITS(1,1,1,1,1,1,1,1), // 78 - 7f 00558 PCK4BITS(2,2,2,2,3,3,3,3), // 80 - 87 00559 PCK4BITS(4,4,4,4,4,4,4,4), // 88 - 8f 00560 PCK4BITS(4,4,4,4,4,4,4,4), // 90 - 97 00561 PCK4BITS(4,4,4,4,4,4,4,4), // 98 - 9f 00562 PCK4BITS(5,5,5,5,5,5,5,5), // a0 - a7 00563 PCK4BITS(5,5,5,5,5,5,5,5), // a8 - af 00564 PCK4BITS(5,5,5,5,5,5,5,5), // b0 - b7 00565 PCK4BITS(5,5,5,5,5,5,5,5), // b8 - bf 00566 PCK4BITS(0,0,6,6,6,6,6,6), // c0 - c7 00567 PCK4BITS(6,6,6,6,6,6,6,6), // c8 - cf 00568 PCK4BITS(6,6,6,6,6,6,6,6), // d0 - d7 00569 PCK4BITS(6,6,6,6,6,6,6,6), // d8 - df 00570 PCK4BITS(7,8,8,8,8,8,8,8), // e0 - e7 00571 PCK4BITS(8,8,8,8,8,9,8,8), // e8 - ef 00572 PCK4BITS(10,11,11,11,11,11,11,11), // f0 - f7 00573 PCK4BITS(12,13,13,13,14,15,0,0) // f8 - ff 00574 }; 00575 00576 00577 static unsigned int UTF8_st [ 26] = { 00578 PCK4BITS(eError,eStart,eError,eError,eError,eError, 12, 10),//00-07 00579 PCK4BITS( 9, 11, 8, 7, 6, 5, 4, 3),//08-0f 00580 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//10-17 00581 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//18-1f 00582 PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe),//20-27 00583 PCK4BITS(eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe),//28-2f 00584 PCK4BITS(eError,eError, 5, 5, 5, 5,eError,eError),//30-37 00585 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//38-3f 00586 PCK4BITS(eError,eError,eError, 5, 5, 5,eError,eError),//40-47 00587 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//48-4f 00588 PCK4BITS(eError,eError, 7, 7, 7, 7,eError,eError),//50-57 00589 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//58-5f 00590 PCK4BITS(eError,eError,eError,eError, 7, 7,eError,eError),//60-67 00591 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//68-6f 00592 PCK4BITS(eError,eError, 9, 9, 9, 9,eError,eError),//70-77 00593 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//78-7f 00594 PCK4BITS(eError,eError,eError,eError,eError, 9,eError,eError),//80-87 00595 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//88-8f 00596 PCK4BITS(eError,eError, 12, 12, 12, 12,eError,eError),//90-97 00597 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//98-9f 00598 PCK4BITS(eError,eError,eError,eError,eError, 12,eError,eError),//a0-a7 00599 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//a8-af 00600 PCK4BITS(eError,eError, 12, 12, 12,eError,eError,eError),//b0-b7 00601 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError),//b8-bf 00602 PCK4BITS(eError,eError,eStart,eStart,eStart,eStart,eError,eError),//c0-c7 00603 PCK4BITS(eError,eError,eError,eError,eError,eError,eError,eError) //c8-cf 00604 }; 00605 00606 static const unsigned int UTF8CharLenTable[] = {0, 1, 0, 0, 0, 0, 2, 3, 00607 3, 3, 4, 4, 5, 5, 6, 6 }; 00608 00609 SMModel UTF8SMModel = { 00610 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UTF8_cls }, 00611 16, 00612 {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, UTF8_st }, 00613 UTF8CharLenTable, 00614 "UTF-8", 00615 }; 00616 } 00617 00618
KDE 4.6 API Reference