📄 f_unicode.c
字号:
#include "f_system.h"
#ifdef _READ_SD_
#include "gb2u_table.h"
#include "gbk2uni.h"
#ifndef GB2312_CODE
#define GB2312_CODE
#endif
#ifndef GBK_CODE
#define GBK_CODE
#endif
/*
u16 MX_Big5ToUnicode(u16 big5)
{
u16 c1, c2;
u32 offset;
u16 unicode;
c1 = (big5>>8)&0x00FF;
c2 = big5&0x00FF;
c2 -= (c2>=0xA1?(0xA1-0x3F):0x40);
offset = ((c1-0x81)*157+c2)*2;
unicode = (((u16)(BtoU[offset+1]))<<8)+(u16)(BtoU[offset]);
return unicode;
}
u16 MX_UnicodeToBig5(u16 unicode)
{
u32 offset;
u16 big5;
if(unicode>0x80)
{
offset = unicode*2;
big5 = (((u16)(UtoB[offset+1]))<<8)+(u16)(UtoB[offset]);
}else{
big5 = unicode;
}
return big5;
}
void MX_UniStrToBig5Str(u16 *unistr, u8 *big5str)
{
u16 i,j;
u16 big5;
i=0;
j=0;
while(unistr[i]!=0x0000)
{
big5=MX_UnicodeToBig5(unistr[i]);
if(big5 > 0x80)
{
big5str[j]=(big5>>8)&0xFF;
big5str[j+1]=(big5&0xFF);
j+=2;
}else{
big5str[j]=(u8)big5;
j++;
}
i++;
}
big5str[j]=0x00;
}
void MX_Big5StrToUniStr(u8 *big5str, u16 *unistr)
{
u16 i,j;
u16 uni;
i=0;
j=0;
while(big5str[i]!=0x00)
{
if(big5str[i]<0x80)
{
unistr[j]=(u16)big5str[i];
i++;
j++;
}else{
uni = (((u16)(big5str[i]))<<8)+(u16)(big5str[i+1]);
unistr[j]=MX_Big5ToUnicode(uni);
i+=2;
j++;
}
}
unistr[j]=0x0000;
}
*/
u16 F_GB2312ToUnicode(u16 gb2312)
{
u32 offset;
u16 unicode=0;
#ifdef GBK_CODE
if(gb2312<=0x00FF)
{
unicode=gb2312;
}
else
{
for(offset=0; offset<GBKTableSize; offset++)
{
if(gb2312 == gbk2uni_table[offset][0])
{
break;
}
}
//if(offset==6768)
if(offset==21791)//Modified by Amy 20080103
{
return 0;
}
else
{
unicode = gbk2uni_table[offset][1];
}
}
return unicode;
#else
if(gb2312<=0x00FF)
{
unicode=gb2312;
}
else
{
for(offset=0; offset<GB2312TableSize; offset++)
{
if(gb2312 == gb2u_table[offset][1])
{
break;
}
}
if(offset==6768)
{
mdt_printf("Can not find gb2312...\n");
return 0;
}
else
{
unicode = gb2u_table[offset][0];
}
}
//mdt_printf("1.BtoU[%d]=%x\n",offset-1, gb2u_table[offset-1]);
//mdt_printf("2.BtoU[%d]=%x\n",offset-1, unicode);
return unicode;
#endif
}
u16 F_UnicodeToGB2312(u16 unicode)
{
u32 offset;
u16 gb2312;
#ifdef GBK_CODE
if(unicode<=0x00FF)
{
gb2312=unicode;
}
else
{
for(offset=0; offset<GBKTableSize; offset++)
{
if(unicode == gbk2uni_table[offset][1])
{
break;
}
}
//if(offset==6768)
if(offset==21791)//Modified by Amy 20080103
{
return 0;
}
else
{
gb2312 = gbk2uni_table[offset][0];
}
}
return gb2312;
#else
if(unicode<=0x00FF)
{
gb2312=unicode;
// mdt_printf("ASCII: %c\n", unicode);
}
else
{
for(offset=0; offset<GB2312TableSize; offset++)
{
if(unicode == gb2u_table[offset][0])
{
break;
}
}
if(offset==6768)
{
mdt_printf("Can not find Unicode...\n");
return 0;
}
else
{
gb2312 = gb2u_table[offset][1];
}
}
// mdt_printf("gb2312=%x\n", gb2312);
return gb2312;
#endif
}
void F_UniStrToGB2312Str(u16 *unistr, u8 *gb2312str)
{
u16 i,j;
u16 gb2312;
i=0;
j=0;
while(unistr[i]!=0x0000)
{
//mdt_printf("unistr[%d]=%x,unistr[%d]=%x\n",i,unistr[i],i+1,unistr[i+1]);
gb2312=F_UnicodeToGB2312(unistr[i]);
if(gb2312 > 0x80)
{
gb2312str[j]=(gb2312>>8)&0xFF;
gb2312str[j+1]=(gb2312&0xFF);
j+=2;
}else{
gb2312str[j]=(u8)gb2312;
j++;
}
i++;
}
//mdt_printf("i=%d,j=%d,Big5=%x,%x,%x,%x\n",i,j,big5str[0], big5str[1], big5str[2],big5str[3]);
gb2312str[j]=0x00;
}
void F_GB2312StrToUniStr(u8 *gb2312str, u16 *unistr)
{
u16 i,j;
u16 uni;
i=0;
j=0;
while(gb2312str[i]!=0x00)
{
if(gb2312str[i]<0x80)
{
unistr[j]=(u16)gb2312str[i];
i++;
j++;
}else{
uni = MDT_2xU8_To_1xU16(gb2312str[i], gb2312str[i+1]);
unistr[j]=F_GB2312ToUnicode(uni);
i+=2;
j++;
}
}
unistr[j]=0x0000; //Denny 2006-12-08
}
#endif /* _READ_SD_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -