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

📄 gbunicode.cpp

📁 Big5,GB,Unicode互相转换的源代码。 C++编写
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/************************************************************************
*
*  Module name         : GBUnicode.cpp
*
*  Module description  :
*     Convert encoding method between GB2312 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    gb2uTable[];
extern const long             gb2uCount;
extern const unsigned char    u2gbTable[];
extern const long             u2gbCount;

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

   if ((*(gbCode + 1) >= 0xa1) && (*(gbCode + 1) <= 0xfe))
   {
      if ((*gbCode >= 0xa1) && (*gbCode <= 0xa9))
      {
         i      = ((*gbCode - 0xa1) * 94 + (*(gbCode + 1) - 0xa1)) * 2;
         mapped = &gb2uTable[i];
      } /* end of if */
      else
      if ((*gbCode >= 0xb0) && (*gbCode <= 0xf7))
      {
         i      = ((*gbCode - 0xb0 + 9) * 94 + (*(gbCode + 1) - 0xa1)) * 2;
         mapped = &gb2uTable[i];
      } /* end of if */
    } /* end of if */

   return mapped;
} // GBCodeToUnicode()

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

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

   return &u2gbTable[i];
} // UnicodeToGBCode()

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

   if ((*(gbCode + 1) >= 0xa1) && (*(gbCode + 1) <= 0xfe))
   {
      if ((*gbCode >= 0xa1) && (*gbCode <= 0xa9))
         answer = TRUE;
      else
      if ((*gbCode >= 0xb0) && (*gbCode <= 0xf7))
         answer = TRUE;
    } /* end of if */

   return answer;
} // IsGBCode()

/************************************************************************
*                       GB2312 to Unicode mapping                       *
************************************************************************/
const unsigned char  gb2uTable[] =
{
   0x30,0x00, 0x30,0x01, 0x30,0x02, 0x30,0xfb, 0x02,0xc9, 0x02,0xc7, 0x00,0xa8,
   0x30,0x03, 0x30,0x05, 0x20,0x15, 0xff,0x5e, 0x22,0x25, 0x20,0x26, 0x20,0x18,
   0x20,0x19, 0x20,0x1c, 0x20,0x1d, 0x30,0x14, 0x30,0x15, 0x30,0x08, 0x30,0x09,
   0x30,0x0a, 0x30,0x0b, 0x30,0x0c, 0x30,0x0d, 0x30,0x0e, 0x30,0x0f, 0x30,0x16,
   0x30,0x17, 0x30,0x10, 0x30,0x11, 0x00,0xb1, 0x00,0xd7, 0x00,0xf7, 0x22,0x36,
   0x22,0x27, 0x22,0x28, 0x22,0x11, 0x22,0x0f, 0x22,0x2a, 0x22,0x29, 0x22,0x08,
   0x22,0x37, 0x22,0x1a, 0x22,0xa5, 0x22,0x25, 0x22,0x20, 0x23,0x12, 0x22,0x99,
   0x22,0x2b, 0x22,0x2e, 0x22,0x61, 0x22,0x4c, 0x22,0x48, 0x22,0x3d, 0x22,0x1d,
   0x22,0x60, 0x22,0x6e, 0x22,0x6f, 0x22,0x64, 0x22,0x65, 0x22,0x1e, 0x22,0x35,
   0x22,0x34, 0x26,0x42, 0x26,0x40, 0x00,0xb0, 0x20,0x32, 0x20,0x33, 0x21,0x03,
   0xff,0x04, 0x00,0xa4, 0xff,0xe0, 0xff,0xe1, 0x20,0x30, 0x00,0xa7, 0x21,0x16,
   0x26,0x06, 0x26,0x05, 0x25,0xcb, 0x25,0xcf, 0x25,0xce, 0x25,0xc7, 0x25,0xc6,
   0x25,0xa1, 0x25,0xa0, 0x25,0xb3, 0x25,0xb2, 0x20,0x3b, 0x21,0x92, 0x21,0x90,
   0x21,0x91, 0x21,0x93, 0x30,0x13, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd,
   0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd,
   0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0x24,0x88, 0x24,0x89,
   0x24,0x8a, 0x24,0x8b, 0x24,0x8c, 0x24,0x8d, 0x24,0x8e, 0x24,0x8f, 0x24,0x90,
   0x24,0x91, 0x24,0x92, 0x24,0x93, 0x24,0x94, 0x24,0x95, 0x24,0x96, 0x24,0x97,
   0x24,0x98, 0x24,0x99, 0x24,0x9a, 0x24,0x9b, 0x24,0x74, 0x24,0x75, 0x24,0x76,
   0x24,0x77, 0x24,0x78, 0x24,0x79, 0x24,0x7a, 0x24,0x7b, 0x24,0x7c, 0x24,0x7d,
   0x24,0x7e, 0x24,0x7f, 0x24,0x80, 0x24,0x81, 0x24,0x82, 0x24,0x83, 0x24,0x84,
   0x24,0x85, 0x24,0x86, 0x24,0x87, 0x24,0x60, 0x24,0x61, 0x24,0x62, 0x24,0x63,
   0x24,0x64, 0x24,0x65, 0x24,0x66, 0x24,0x67, 0x24,0x68, 0x24,0x69, 0xff,0xfd,
   0xff,0xfd, 0x32,0x20, 0x32,0x21, 0x32,0x22, 0x32,0x23, 0x32,0x24, 0x32,0x25,
   0x32,0x26, 0x32,0x27, 0x32,0x28, 0x32,0x29, 0xff,0xfd, 0xff,0xfd, 0x21,0x60,
   0x21,0x61, 0x21,0x62, 0x21,0x63, 0x21,0x64, 0x21,0x65, 0x21,0x66, 0x21,0x67,
   0x21,0x68, 0x21,0x69, 0x21,0x6a, 0x21,0x6b, 0xff,0xfd, 0xff,0xfd, 0xff,0x01,
   0xff,0x02, 0xff,0x03, 0xff,0xe5, 0xff,0x05, 0xff,0x06, 0xff,0x07, 0xff,0x08,
   0xff,0x09, 0xff,0x0a, 0xff,0x0b, 0xff,0x0c, 0xff,0x0d, 0xff,0x0e, 0xff,0x0f,
   0xff,0x10, 0xff,0x11, 0xff,0x12, 0xff,0x13, 0xff,0x14, 0xff,0x15, 0xff,0x16,
   0xff,0x17, 0xff,0x18, 0xff,0x19, 0xff,0x1a, 0xff,0x1b, 0xff,0x1c, 0xff,0x1d,
   0xff,0x1e, 0xff,0x1f, 0xff,0x20, 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,0x3b, 0xff,0x3c, 0xff,0x3d, 0xff,0x3e, 0xff,0x3f, 0xff,0x40,
   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, 0xff,0x5b, 0xff,0x5c,
   0xff,0x5d, 0xff,0xe3, 0x30,0x41, 0x30,0x42, 0x30,0x43, 0x30,0x44, 0x30,0x45,
   0x30,0x46, 0x30,0x47, 0x30,0x48, 0x30,0x49, 0x30,0x4a, 0x30,0x4b, 0x30,0x4c,
   0x30,0x4d, 0x30,0x4e, 0x30,0x4f, 0x30,0x50, 0x30,0x51, 0x30,0x52, 0x30,0x53,
   0x30,0x54, 0x30,0x55, 0x30,0x56, 0x30,0x57, 0x30,0x58, 0x30,0x59, 0x30,0x5a,
   0x30,0x5b, 0x30,0x5c, 0x30,0x5d, 0x30,0x5e, 0x30,0x5f, 0x30,0x60, 0x30,0x61,
   0x30,0x62, 0x30,0x63, 0x30,0x64, 0x30,0x65, 0x30,0x66, 0x30,0x67, 0x30,0x68,
   0x30,0x69, 0x30,0x6a, 0x30,0x6b, 0x30,0x6c, 0x30,0x6d, 0x30,0x6e, 0x30,0x6f,
   0x30,0x70, 0x30,0x71, 0x30,0x72, 0x30,0x73, 0x30,0x74, 0x30,0x75, 0x30,0x76,
   0x30,0x77, 0x30,0x78, 0x30,0x79, 0x30,0x7a, 0x30,0x7b, 0x30,0x7c, 0x30,0x7d,
   0x30,0x7e, 0x30,0x7f, 0x30,0x80, 0x30,0x81, 0x30,0x82, 0x30,0x83, 0x30,0x84,
   0x30,0x85, 0x30,0x86, 0x30,0x87, 0x30,0x88, 0x30,0x89, 0x30,0x8a, 0x30,0x8b,
   0x30,0x8c, 0x30,0x8d, 0x30,0x8e, 0x30,0x8f, 0x30,0x90, 0x30,0x91, 0x30,0x92,
   0x30,0x93, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd,
   0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0xff,0xfd, 0x30,0xa1, 0x30,0xa2,
   0x30,0xa3, 0x30,0xa4, 0x30,0xa5, 0x30,0xa6, 0x30,0xa7, 0x30,0xa8, 0x30,0xa9,
   0x30,0xaa, 0x30,0xab, 0x30,0xac, 0x30,0xad, 0x30,0xae, 0x30,0xaf, 0x30,0xb0,
   0x30,0xb1, 0x30,0xb2, 0x30,0xb3, 0x30,0xb4, 0x30,0xb5, 0x30,0xb6, 0x30,0xb7,
   0x30,0xb8, 0x30,0xb9, 0x30,0xba, 0x30,0xbb, 0x30,0xbc, 0x30,0xbd, 0x30,0xbe,
   0x30,0xbf, 0x30,0xc0, 0x30,0xc1, 0x30,0xc2, 0x30,0xc3, 0x30,0xc4, 0x30,0xc5,

⌨️ 快捷键说明

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