mbcssm.cpp

来自「判断一串字符是属于什么字符集的程序」· C++ 代码 · 共 611 行 · 第 1/2 页

CPP
611
字号
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 PRUint32 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 PRUint32 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",};// sjisstatic PRUint32 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 PRUint32 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 PRUint32 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 PRUint32 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 PRUint32 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 PRUint32 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 PRUint32 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 PRUint32 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 PRUint32 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 PRUint32 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 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(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 PRUint32 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 PRUint32 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",};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?