Chinaunix首页 | 论坛 | 博客
  • 博客访问: 438639
  • 博文数量: 132
  • 博客积分: 2511
  • 博客等级: 大尉
  • 技术积分: 1385
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-11 15:10
文章分类

全部博文(132)

文章存档

2012年(18)

2011年(35)

2010年(60)

2009年(19)

分类: LINUX

2010-02-09 13:45:45

包子给的一段代码,哈哈。。


UTF82Unicode(const unsigned char* ib, int & iLen, unsigned char* ob,int &n)
{
    n=0;
    for(int i=0; i<iLen; i++)
    {
        if(ib[i]>>7==0)
        {
            ob[n++]=ib[i];
            ob[n++]=0;
        }
        else if(ib[i]>=240)
        {
            unsigned short x=ib[i]&0xF;
            x<<=6;
            x|=ib[i+1]&0x3F;
            x<<=6;
            x|=ib[i+2]&0x3f;
            x<<=6;
            x|=ib[i+3]&0x3f;
            ob[n++]=x&0xFF;
            ob[n++]=(x>>8)&0xFF;
            i+=3;
        }
        else if(ib[i]>=224)
        {
            unsigned short x=ib[i]&0xF;
            x<<=6;
            x|=ib[i+1]&0x3F;
            x<<=6;
            x|=ib[i+2]&0x3F;
            ob[n++]=x&0xFF;
            ob[n++]=(x>>8)&0xFF;
            i+=2;
        }
        else if(ib[i]>=192)
        {
            unsigned short x=ib[i]&0x3F;
            x<<=6;
            x|=ib[i+1]&0x3F;
            ob[n++]=x&0xFF;
            ob[n++]=(x>>8)&0xFF;
            i++;
        }
    }
    n = n/2;
}


阅读(1238) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~