⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 big5unicode.cpp

📁 Big5,GB,Unicode互相转换的源代码。 C++编写
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/************************************************************************
*
*  Module name         : Big5Unicode.cpp
*
*  Module description  :
*     Convert encoding method between BIG5 and Unicode.
*
*  Project             : Generic
*
*  Target platform     : Win32
*
*  Compiler & Library  : Visual C++ 6.0
*
*  Author              : Richard Shen
*
*  Creation date       : 09 October, 2000
*
************************************************************************/
#include <windows.h>
#include "GBBig5Unicode.h"

// These "extern"s are actually in this file
extern const unsigned char    b2uTable[];
extern const long             b2uCount;
extern const unsigned char    u2bTable[];
extern const long             u2bCount;

/************************************************************************
*  Function name   : Big5CodeToUnicode
*  Description     : Map BIG5 code to Unicode.
*                  :
*  Parameters      : b5Code   - The BIG5 code.
*  Returns         : The mapped Unicode.  NULL if error.
*  Author          : Richard Shen
* ----------------------------------------------------------------------
*  Date     By       Description
* ----------------------------------------------------------------------
*  09Oct00  RCS      Created.
************************************************************************/
const unsigned char *Big5CodeToUnicode(unsigned char *b5Code)
{
   const unsigned char  *mapped = 0;
   unsigned int         i;

   if ((*b5Code >= 0xa1) && (*b5Code <= 0xfe))
   {
      if ((*(b5Code + 1) >= 0x40) && (*(b5Code + 1) <= 0x7e))
      {
         i      = ((*b5Code - 0xa1) * 157 + (*(b5Code + 1) - 0x40)) * 2;
         mapped = &b2uTable[i];
      } /* end of if */
      else
      if ((*(b5Code + 1) >= 0xa1) && (*(b5Code + 1) <= 0xfe))
      {
         i      = ((*b5Code - 0xa1) * 157 + (*(b5Code + 1) - 0xa1 ) + 63) * 2;
         mapped = &b2uTable[i];
      } /* end of if */
   } /* end of if */

   return mapped;
} // Big5CodeToUnicode()

/************************************************************************
*  Function name   : UnicodeToBig5Code
*  Description     : Map Unicode to BIG5 code.
*                  :
*  Parameters      : unicode  - The Unicode.
*  Returns         : The mapped GBCode.  NULL if error.
*  Author          : Richard Shen
* ----------------------------------------------------------------------
*  Date     By       Description
* ----------------------------------------------------------------------
*  09Oct00  RCS      Created.
************************************************************************/
const unsigned char *UnicodeToBig5Code(unsigned char *unicode)
{
   unsigned int   i;

   i = ((*unicode << 8) + *(unicode + 1)) * 2;

   return &u2bTable[i];
} // UnicodeToBig5Code()

/************************************************************************
*  Function name   : IsBig5Code
*  Description     : Check whether it is a BIG5 code.
*                  :
*  Parameters      : b5Code   - The code (2 bytes).
*  Returns         : TRUE     - Is BIG5 code.
*                  : FALSE    - Non BIG5 code.
*  Author          : Richard Shen
* ----------------------------------------------------------------------
*  Date     By       Description
* ----------------------------------------------------------------------
*  20Oct00  RCS      Created.
************************************************************************/
BOOL IsBig5Code(unsigned char *b5Code)
{
   BOOL     answer = FALSE;

   if ((*b5Code >= 0xa1) && (*b5Code <= 0xfe))
   {
      if ((*(b5Code + 1) >= 0x40) && (*(b5Code + 1) <= 0x7e))
         answer = TRUE;
      else
      if ((*(b5Code + 1) >= 0xa1) && (*(b5Code + 1) <= 0xfe))
         answer = TRUE;
   } /* end of if */

   return answer;
} // IsBig5Code()

/************************************************************************
*                       BIG5 to Unicode mapping                         *
************************************************************************/
const unsigned char  b2uTable[] =
{
   0x30,0x00, 0xff,0x0c, 0x30,0x01, 0x30,0x02, 0xff,0x0e, 0x20,0x22, 0xff,0x1b,
   0xff,0x1a, 0xff,0x1f, 0xff,0x01, 0xfe,0x30, 0x20,0x26, 0x20,0x25, 0xfe,0x50,
   0xff,0x64, 0xfe,0x52, 0x00,0xb7, 0xfe,0x54, 0xfe,0x55, 0xfe,0x56, 0xfe,0x57,
   0xff,0x5c, 0x20,0x13, 0xfe,0x31, 0x20,0x14, 0xfe,0x33, 0xff,0xfd, 0xfe,0x34,
   0xfe,0x4f, 0xff,0x08, 0xff,0x09, 0xfe,0x35, 0xfe,0x36, 0xff,0x5b, 0xff,0x5d,
   0xfe,0x37, 0xfe,0x38, 0x30,0x14, 0x30,0x15, 0xfe,0x39, 0xfe,0x3a, 0x30,0x10,
   0x30,0x11, 0xfe,0x3b, 0xfe,0x3c, 0x30,0x0a, 0x30,0x0b, 0xfe,0x3d, 0xfe,0x3e,
   0x30,0x08, 0x30,0x09, 0xfe,0x3f, 0xfe,0x40, 0x30,0x0c, 0x30,0x0d, 0xfe,0x41,
   0xfe,0x42, 0x30,0x0e, 0x30,0x0f, 0xfe,0x43, 0xfe,0x44, 0xfe,0x59, 0xfe,0x5a,
   0xfe,0x5b, 0xfe,0x5c, 0xfe,0x5d, 0xfe,0x5e, 0x20,0x18, 0x20,0x19, 0x20,0x1c,
   0x20,0x1d, 0x30,0x1d, 0x30,0x1e, 0x20,0x35, 0x20,0x32, 0xff,0x03, 0xff,0x06,
   0xff,0x0a, 0x20,0x3b, 0x00,0xa7, 0x30,0x03, 0x25,0xcb, 0x25,0xcf, 0x25,0xb3,
   0x25,0xb2, 0x25,0xce, 0x26,0x06, 0x26,0x05, 0x25,0xc7, 0x25,0xc6, 0x25,0xa1,
   0x25,0xa0, 0x25,0xbd, 0x25,0xbc, 0x32,0xa3, 0x21,0x05, 0x20,0x3e, 0xff,0xfd,
   0xff,0x3f, 0xff,0xfd, 0xfe,0x49, 0xfe,0x4a, 0xfe,0x4d, 0xfe,0x4e, 0xfe,0x4b,
   0xfe,0x4c, 0xfe,0x5f, 0xfe,0x60, 0xfe,0x61, 0xff,0x0b, 0xff,0x0d, 0x00,0xd7,
   0x00,0xf7, 0x00,0xb1, 0x22,0x1a, 0xff,0x1c, 0xff,0x1e, 0xff,0x1d, 0x22,0x66,
   0x22,0x67, 0x22,0x60, 0x22,0x1e, 0x22,0x52, 0x22,0x61, 0xfe,0x62, 0xfe,0x63,
   0xfe,0x64, 0xfe,0x65, 0xfe,0x66, 0x22,0x3c, 0x22,0x29, 0x22,0x2a, 0x22,0xa5,
   0x22,0x20, 0x22,0x1f, 0x22,0xbf, 0x33,0xd2, 0x33,0xd1, 0x22,0x2b, 0x22,0x2e,
   0x22,0x35, 0x22,0x34, 0x26,0x40, 0x26,0x42, 0x26,0x41, 0x26,0x09, 0x21,0x91,
   0x21,0x93, 0x21,0x90, 0x21,0x92, 0x21,0x96, 0x21,0x97, 0x21,0x99, 0x21,0x98,
   0x22,0x25, 0x22,0x23, 0xff,0xfd, 0xff,0xfd, 0xff,0x0f, 0xff,0x3c, 0xff,0x04,
   0x00,0xa5, 0x30,0x12, 0x00,0xa2, 0x00,0xa3, 0xff,0x05, 0xff,0x20, 0x21,0x03,
   0x21,0x09, 0xfe,0x69, 0xfe,0x6a, 0xfe,0x6b, 0x33,0xd5, 0x33,0x9c, 0x33,0x9d,
   0x33,0x9e, 0x33,0xce, 0x33,0xa1, 0x33,0x8e, 0x33,0x8f, 0x33,0xc4, 0x00,0xb0,
   0x51,0x59, 0x51,0x5b, 0x51,0x5e, 0x51,0x5d, 0x51,0x61, 0x51,0x63, 0x55,0xe7,
   0x74,0xe9, 0x7c,0xce, 0x25,0x81, 0x25,0x82, 0x25,0x83, 0x25,0x84, 0x25,0x85,
   0x25,0x86, 0x25,0x87, 0x25,0x88, 0x25,0x8f, 0x25,0x8e, 0x25,0x8d, 0x25,0x8c,
   0x25,0x8b, 0x25,0x8a, 0x25,0x89, 0x25,0x3c, 0x25,0x34, 0x25,0x2c, 0x25,0x24,
   0x25,0x1c, 0x25,0x94, 0x25,0x00, 0x25,0x02, 0x25,0x95, 0x25,0x0c, 0x25,0x10,
   0x25,0x14, 0x25,0x18, 0x25,0x6d, 0x25,0x6e, 0x25,0x70, 0x25,0x6f, 0x25,0x50,
   0x25,0x5e, 0x25,0x6a, 0x25,0x61, 0x25,0xe2, 0x25,0xe3, 0x25,0xe5, 0x25,0xe4,
   0x25,0x71, 0x25,0x72, 0x25,0x73, 0xff,0x10, 0xff,0x11, 0xff,0x12, 0xff,0x13,
   0xff,0x14, 0xff,0x15, 0xff,0x16, 0xff,0x17, 0xff,0x18, 0xff,0x19, 0x21,0x60,
   0x21,0x61, 0x21,0x62, 0x21,0x63, 0x21,0x64, 0x21,0x65, 0x21,0x66, 0x21,0x67,
   0x21,0x68, 0x21,0x69, 0x30,0x21, 0x30,0x22, 0x30,0x23, 0x30,0x24, 0x30,0x25,
   0x30,0x26, 0x30,0x27, 0x30,0x28, 0x30,0x29, 0xff,0xfd, 0x53,0x44, 0xff,0xfd,
   0xff,0x21, 0xff,0x22, 0xff,0x23, 0xff,0x24, 0xff,0x25, 0xff,0x26, 0xff,0x27,
   0xff,0x28, 0xff,0x29, 0xff,0x2a, 0xff,0x2b, 0xff,0x2c, 0xff,0x2d, 0xff,0x2e,
   0xff,0x2f, 0xff,0x30, 0xff,0x31, 0xff,0x32, 0xff,0x33, 0xff,0x34, 0xff,0x35,
   0xff,0x36, 0xff,0x37, 0xff,0x38, 0xff,0x39, 0xff,0x3a, 0xff,0x41, 0xff,0x42,
   0xff,0x43, 0xff,0x44, 0xff,0x45, 0xff,0x46, 0xff,0x47, 0xff,0x48, 0xff,0x49,
   0xff,0x4a, 0xff,0x4b, 0xff,0x4c, 0xff,0x4d, 0xff,0x4e, 0xff,0x4f, 0xff,0x50,
   0xff,0x51, 0xff,0x52, 0xff,0x53, 0xff,0x54, 0xff,0x55, 0xff,0x56, 0xff,0x57,
   0xff,0x58, 0xff,0x59, 0xff,0x5a, 0x03,0x91, 0x03,0x92, 0x03,0x93, 0x03,0x94,
   0x03,0x95, 0x03,0x96, 0x03,0x97, 0x03,0x98, 0x03,0x99, 0x03,0x9a, 0x03,0x9b,
   0x03,0x9c, 0x03,0x9d, 0x03,0x9e, 0x03,0x9f, 0x03,0xa0, 0x03,0xa1, 0x03,0xa3,
   0x03,0xa4, 0x03,0xa5, 0x03,0xa6, 0x03,0xa7, 0x03,0xa8, 0x03,0xa9, 0x03,0xb1,
   0x03,0xb2, 0x03,0xb3, 0x03,0xb4, 0x03,0xb5, 0x03,0xb6, 0x03,0xb7, 0x03,0xb8,
   0x03,0xb9, 0x03,0xba, 0x03,0xbb, 0x03,0xbc, 0x03,0xbd, 0x03,0xbe, 0x03,0xbf,
   0x03,0xc0, 0x03,0xc1, 0x03,0xc3, 0x03,0xc4, 0x03,0xc5, 0x03,0xc6, 0x03,0xc7,
   0x03,0xc8, 0x03,0xc9, 0x31,0x05, 0x31,0x06, 0x31,0x07, 0x31,0x08, 0x31,0x09,
   0x31,0x0a, 0x31,0x0b, 0x31,0x0c, 0x31,0x0d, 0x31,0x0e, 0x31,0x0f, 0x31,0x10,
   0x31,0x11, 0x31,0x12, 0x31,0x13, 0x31,0x14, 0x31,0x15, 0x31,0x16, 0x31,0x17,
   0x31,0x18, 0x31,0x19, 0x31,0x1a, 0x31,0x1b, 0x31,0x1c, 0x31,0x1d, 0x31,0x1e,
   0x31,0x1f, 0x31,0x20, 0x31,0x21, 0x31,0x22, 0x31,0x23, 0x31,0x24, 0x31,0x25,
   0x31,0x26, 0x31,0x27, 0x31,0x28, 0x31,0x29, 0x02,0xd9, 0x02,0xc9, 0x02,0xca,

⌨️ 快捷键说明

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