📄 mbcssm.cpp
字号:
/* libcharguess - Guess the encoding/charset of a string Copyright (C) 2003 Stephane Corbe <noubi@users.sourceforge.net> Based on Mozilla sources This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include "codingStateMachine.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 static PRUint32 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 valuePCK4BITS(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 PRUint32 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 PRUint32 Big5CharLenTable[] = {0, 1, 1, 2, 0};SMModel Big5SMModel = { {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, BIG5_cls }, 5, {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, BIG5_st }, Big5CharLenTable, "Big5",};static PRUint32 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 PRUint32 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 PRUint32 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 PRUint32 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 PRUint32 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 PRUint32 EUCKRCharLenTable[] = {0, 1, 2, 0};SMModel EUCKRSMModel = { {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCKR_cls }, 4, {eIdxSft4bits, eSftMsk4bits, eBitSft4bits, eUnitMsk4bits, EUCKR_st }, EUCKRCharLenTable, "EUC-KR",};static PRUint32 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 PRUint32 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 PRUint32 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 gb18030static PRUint32 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 PRUint32 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 PRUint32 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 PRUint32 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -