首页 > 开发 > 综合 > 正文

UnicodeToUTF8

2024-07-21 02:22:05
字体:
来源:转载
供稿:网友
  • 网站运营seo文章大全
  • 提供全面的站长运营经验及seo技术!
  • convertunicodetoutf8(const wchar *wstrin, byte *buff,int vlen)
    {
        assert(wstrin);
        int wlen=wcslen(wstrin);
        int i=0;
    #define putchar(a)     buff[i++]=(byte)a;

        for(int j=0;(dword)j<wcslen(wstrin);j++)
        {
            assert(i<vlen);
            wchar c=wstrin[j];
            if (c < 0x80)
            {
                putchar (c);
            }
            else if (c < 0x800)
            {
                putchar (0xc0 | c>>6);
                putchar (0x80 | c & 0x3f);
            }
            else if (c < 0x10000)
            {
                putchar (0xe0 | c>>12);
                putchar (0x80 | c>>6 & 0x3f);
                putchar (0x80 | c & 0x3f);
            }
            else if (c < 0x200000)
            {
                putchar (0xf0 | c>>18);
                putchar (0x80 | c>>12 & 0x3f);
                putchar (0x80 | c>>6 & 0x3f);
                putchar (0x80 | c & 0x3f);
            }
        }
    }
    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表