// UCS2GBK.cpp: implementation of the UCS2GBK class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TransTool.h"
#include "UCS2GBK.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
UCS2GBK::UCS2GBK()
{
}
UCS2GBK::~UCS2GBK()
{
}
// ucs2GB.c
// unic <==>gbk
/*************************
*
*
***************************/
extern const unsigned short unic2gbk_table[];
extern const unsigned short gbk2unic_table[];
int UCS2GBK::Unicode2GBK(short *unicode,unsigned short slen,unsigned char *GBK,unsigned short dlen)// return strlen
{
unsigned short *pu;
unsigned char *pc;
unsigned short cc;
unsigned short sl=0,dl=0;
int count = 0;
pu=(unsigned short *)unicode;
pc=GBK;
while(*pu)
{
if(*pu<0x80)
{
if((dl+1)<dlen)
{
*pc++=(unsigned char)*pu++;
sl++; dl++;
}
else
break;
}
else if(*pu>=0x4e00)
{
cc=unic2gbk_table[*pu-0x4e00];
pu++;
sl++;
if((dl+2)<dlen)
{
*pc++=cc>>8;
*pc++=cc&0xff;
dl+=2;
}
else
break;
}
else
{
pu++; // lost it , 128--0x4e00 , do not valid at GBK , not complete ,need reference the GBK table
sl++;
}
}
*pc=0;
return pc-GBK;
}
#define LINE_NUM 8
int UCS2GBK::GBK2Unicode(unsigned char *GBK,unsigned short slen,unsigned char *unicode,unsigned short dlen)
{
unsigned short *pu;
unsigned char *pc;
unsigned short cc[LINE_NUM];
unsigned short sl=0,dl=0;
char str[20];
int count = 0, cnt=0;
int offset = 10;
//pu=unicode;
pc=GBK;
memset(str,0,20);
while(*pc)
{
if(*pc<0x80)
{
if((dl+1)<dlen)
{
//*pu++=*pc++;
cc[count] = *pc++;
sl++; dl++;
sprintf(str,"0x%02X,0x%02X,",(unsigned char)((cc[count]&0xff00)>>8),(unsigned char)(cc[count]&0xff));
cnt++;
memcpy((char*)(unicode+offset),str,strlen(str));
offset += strlen(str);
memset(str,0,20);
count ++;
if(count == LINE_NUM)
{
memcpy((char*)(unicode+offset),"\r\n",2);
offset += 2;
count = 0;
}
}
else
break;
}
else
if(*pc>=0x81 && *(pc+1)>=0x40)
{
if((dl+1)<dlen)
{
//*pu++=gbk2unic_table[((*pc-0x80)<<8)+*(pc+1)];
cc[count]=gbk2unic_table[((*pc-0x80)<<8)+*(pc+1)];
pc+=2;
sl+=2; dl++;
sprintf(str,"0x%02X,0x%02X,",(unsigned char)((cc[count]&0xff00)>>8),(unsigned char)(cc[count]&0xff));
cnt++;
memcpy((char*)(unicode+offset),str,strlen(str));
offset += strlen(str);
memset(str,0,20);
count ++;
if(count == LINE_NUM)
{
memcpy((char*)(unicode+offset),"\r\n",2);
offset += 2;
count = 0;
}
}
else
break;
}
else //in valid ??
{
pc+=2;
sl+=2;
}
}
sprintf(str,"0x%02X,0x%02X,",(unsigned char)((cnt&0xff00)>>8),(unsigned char)(cnt&0xff));
memset(unicode,' ',10);
memcpy(unicode,str,strlen(str));
unicode[offset] = 0;
//*pu=0;
return 1;
}
// unic2gbk : gbkcode= unic2gbk_table[uniccode-0x4e00]
const unsigned short unic2gbk_table[]={
0xd2bb,0xb6a1,0x8140,0xc6df,0x8141,0x8142,0x8143,0xcdf2,0xd5c9,0xc8fd,0xc9cf,0xcfc2,0xd8a2,0xb2bb,0xd3eb,0x8144,
0xd8a4,0xb3f3,0x8145,0xd7a8,0xc7d2,0xd8a7,0xcac0,0x8146,0xc7f0,0xb1fb,0xd2b5,0xb4d4,0xb6ab,0xcbbf,0xd8a9,0x8147,
0x8148,0x8149,0xb6aa,0x814a,0xc1bd,0xd1cf,0x814b,0xc9a5,0xd8ad,0x814c,0xb8f6,0xd1be,0xe3dc,0xd6d0,0x814d,0x814e,
0xb7e1,0x814f,0xb4ae,0x8150,0xc1d9,0x8151,0xd8bc,0x8152,0xcde8,0xb5a4,0xceaa,0xd6f7,0x8153,0xc0f6,0xbed9,0xd8af,
0x8154,0x8155,0x8156,0xc4cb,0x8157,0xbec3,0x8158,0xd8b1,0xc3b4,0xd2e5,0x8159,0xd6ae,0xceda,0xd5a7,0xbaf5,0xb7a6,
0xc0d6,0x815a,0xc6b9,0xc5d2,0xc7c7,0x815b,0xb9d4,0x815c,0xb3cb,0xd2d2,0x815d,0x815e,0xd8bf,0xbec5,0xc6f2,0xd2b2,
0xcfb0,0xcfe7,0x815f,0x8160,0x8161,0x8162,0xcae9,0x8163,0x8164,0xd8c0,0x8165,0x8166,0x8167,0x8168,0x8169,0x816a,
0xc2f2,0xc2d2,0x816b,0xc8e9,0x816c,0x816d,0x816e,0x816f,0x8170,0x8171,0x8172,0x8173,0x8174,0x8175,0xc7ac,0x8176,
0x8177,0x8178,0x8179,0x817a,0x817b,0x817c,0xc1cb,0x817d,0xd3e8,0xd5f9,0x817e,0xcac2,0xb6fe,0xd8a1,0xd3da,0xbff7,
0x8180,0xd4c6,0xbba5,0xd8c1,0xcee5,0xbeae,0x8181,0x8182,0xd8a8,0x8183,0xd1c7,0xd0a9,0x8184,0x8185,0x8186,0xd8bd,
0xd9ef,0xcdf6,0xbfba,0x8187,0xbdbb,0xbaa5,0xd2e0,0xb2fa,0xbae0,0xc4b6,0x8188,0xcfed,0xbea9,0xcda4,0xc1c1,0x8189,
0x818a,0x818b,0xc7d7,0xd9f1,0x818c,0xd9f4,0x818d,0x818e,0x818f,0x8190,0xc8cb,0xd8e9,0x8191,0x8192,0x8193,0xd2da,
0xcab2,0xc8ca,0xd8ec,0xd8ea,0xd8c6,0xbdf6,0xc6cd,0xb3f0,0x8194,0xd8eb,0xbdf1,0xbde9,0x8195,0xc8d4,0xb4d3,0x8196,
0x8197,0xc2d8,0x8198,0xb2d6,0xd7d0,0xcacb,0xcbfb,0xd5cc,0xb8b6,0xcfc9,0x8199,0x819a,0x819b,0xd9da,0xd8f0,0xc7aa,
0x819c,0xd8ee,0x819d,0xb4fa,0xc1ee,0xd2d4,0x819e,0x819f,0xd8ed,0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ee,0xb3de,0xd9a8,0x81ef,0xc0fd,0x81f0,0xcacc,0x81f1,0xd9aa,
0x81f2,0xd9a7,0x81f3,0x81f4,0xd9b0,0x81f5,0x81f6,0xb6b1,0x81f7,0x81f8,0x81f9,0xb9a9,0x81fa,0xd2c0,0x81fb,0x81fc,
0xcfc0,0x81fd,0x81fe,0xc2c2,0x8240,0xbdc4,0xd5ec,0xb2e0,0xc7c8,0xbfeb,0xd9ad,0x8241,0xd9af,0x8242,0xceea,0xbaee,
0x8243,0x8244,0x8245,0x8246,0x8247,0xc7d6,0x8248,0x8249,0x824a,0x824b,0x824c,0x824d,0x824e,0x824f,0x8250,0xb1e3,
0x8251,0x8252,0x8253,0xb4d9,0xb6ed,0xd9b4,0x8254,0x8255,0x8256,0x8257,0xbfa1,0x8258,0x8259,0x825a,0xd9de,0xc7ce,
0xc0fe,0xd9b8,0x825b,0x825c,0x825d,0x825e,0x825f,0xcbd7,0xb7fd,0x8260,0xd9b5,0x8261,0xd9b7,0xb1a3,0xd3e1,0xd9b9,
0x8262,0xd0c5,0x8263,0xd9b6,0x8264,0x8265,0xd9b1,0x8266,0xd9b2,0xc1a9,0xd9b3,0x8267,0x8268,0xbcf3,0xd0de,0xb8a9,
0x8269,0xbee3,0x826a,0xd9bd,0x826b,0x826c,0x826d,0x826e,0xd9ba,0x826f,0xb0b3,0x8270,0x8271,0x8272,0xd9c2,0x8273,
0x8274,0x8275,0x8276,0x8277,0x8278,0x8279,0x827a,0x827b,0x827c,0x827d,0x827e,0x8280,0xd9c4,0xb1b6,0x8281,0xd9bf,
0x8282,0x8283,0xb5b9,0x8284,0xbef3,0x8285,0x8286,0x8287,0xccc8,0xbaf2,0xd2d0,0x8288,0xd9c3,0x8289,0x828a,0xbde8,
0x828b,0xb3ab,0x828c,0x828d,0x828e,0xd9c5,0xbeeb,0x828f,0xd9c6,0xd9bb,0xc4df,0x8290,0xd9be,0xd9c1,0xd9c0,0x8291,
0x8292,0x8293,0x8294,0x8295,0x8296,0x8297,0x8298,0x8299,0x829a,0x829b,0xd5ae,0x829c,0xd6b5,0x829d,0xc7e3,0x829e,
0x829f,0x82a0,0x82a1,0xd9c8,0x82a2,0x82a3,0x82a4,0xbcd9,0xd9ca,0x82a5,0x82a6,0x82a7,0xd9bc,0x82a8,0xd9cb,0xc6ab,
0x82a9,0x82aa,0x82ab,0x82ac,0x82ad,0xd9c9,0x82ae,0x82af,0x82b0,0x82b1,0xd7f6,0x82b2,0xcda3,0x82b3,0x82b4,0x82b5,
0x82b6,0x82b7,0x82b8,0x82b9,0x82ba,0xbda1,0x82bb,0x82bc,0x82bd,0x82be,0x82bf,0x82c0,0xd9cc,0x82c1,0x82c2,0x82c3,
0x82c4,0x82c5,0x82c6,0x82c7,0x82c8,0x82c9,0xc5bc,0xcdb5,0x82ca,0x82cb,0x82cc,0xd9cd,0x82cd,0x82ce,0xd9c7,0xb3a5,
0xbffe,0x82cf,0x82d0,0x82d1,0x82d2,0xb8b5,0x82d3,0x82d4,0xc0fc,
ucs2Gbk互转的code_自己写的
5星 · 超过95%的资源 需积分: 11 27 浏览量
2009-02-07
23:04:18
上传
评论
收藏 94KB RAR 举报
feel48
- 粉丝: 0
- 资源: 2
最新资源
- 基于 Java的班级管理系统课程设计
- 深入探索Suno AI:教程、元标签与案例分析.pdf
- 超市会员积分管理系统主要用于实现了企业管理数据统计等
- 基于 Java的班级管理系统
- MyBatis 动态 SQL:灵活而强大的查询构建器.pdf
- com.accordion.prettyo.apk
- 毕业设计:基于SSM的mysql-ssm软件bug管理系统(源码 + 数据库 + 说明文档)
- MTSQL8.0.35windows(64bit)-mysql-installer-community-8.0.35.0
- 人工智能引领音乐创作新时代之Suno AI
- Public-bicycle-usage-forecast-master.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论3