UTF8转Unicode
来源:互联网 发布:matlab最优化算法例题 编辑:程序博客网 时间:2024/05/22 08:25
int GetUtf8ByteNumForWord(char firstCh){ int nRet=0; __asm { movzx ecx,byte ptr[firstCh] and ecx,0xE0 jz done test ecx,0x80 jnz lbm mov nRet,1 jmp donelbm: cmp cl,0xE0 jz lb3 cmp cl,0x0C jz lb2 jmp donelb3: mov nRet,3 jmp donelb2: mov nRet,2done: } return nRet;}void Utf8ToUnicode(const char* utf8, int len, wchar_t *unicode){ int i = 0; int j = 0; char* temp=(char*)unicode; //循环解析 while (i < len) { int nByteNum=GetUtf8ByteNumForWord(utf8[i]); if (nByteNum==0) { return; } switch(nByteNum) { case 1: temp[j] = utf8[i]; temp[j+1]=0; break; case 2: temp[j] = utf8[i]; temp[j + 1] = utf8[i + 1]; break; case 3: //这里就开始进行UTF8->Unicode temp[j + 1] = ((utf8[i] & 0x0F) << 4) | ((utf8[i + 1] >> 2) & 0x0F); temp[j] = ((utf8[i + 1] & 0x03) << 6) + (utf8[i + 2] & 0x3F); break; default: break; } j+=2; i+=nByteNum; } temp[j]=0; temp[j+1]=0;}
测试代码如下:
std::ifstream fin("debug\\Test.txt");const unsigned int L_MAX_LINE=1024;char utf8[L_MAX_LINE];wchar_t unicode[L_MAX_LINE];while(fin.getline(utf8,L_MAX_LINE)){ Utf8ToUnicode(utf8,strlen(utf8),unicode); MessageBoxW(0,unicode,0,0);}fin.close();
阅读全文
0 0
- Unicode转UTF8
- utf8 转 unicode
- UTF8转unicode
- UNICODE 转 UTF8
- utf8转unicode
- unicode转utf8
- utf8转unicode
- utf8转unicode
- PHP UNICODE 转 UTF8
- unicode转UTF8
- unicode 转 utf8
- UTF8转Unicode
- unicode码表 及 unicode转utf8规则
- unicode码表 及 unicode转utf8规则
- unicode码表 及 unicode转utf8规则
- Asc转UTF8及Unicode
- unicode 转 utf8, WideCharToMultiByte MultiByteToWideChar
- UTF8 转 UNICODE GBK ANSI
- 一脸懵逼学习KafKa集群的安装搭建--(一种高吞吐量的分布式发布订阅消息系统)
- 使用太乐地图下载器下载百度地图切片
- windows端加密程序,lua代码,ZeroBrane调试
- 小测试反省
- spring启动异常:org.springframework.beans.factory.BeanCreationException
- UTF8转Unicode
- 用IOT的思维来管理我们的查看我们重要业务的服务器健康状态-脚本功能性测试!
- JavaWeb将验证码转换为Base64格式字符串输出到前端
- PostgreSQL的MVCC与xmin,xmax----数据架构师的PostgreSQL修炼
- 写给自己的JAVA工程师之路-枚举
- JavaFX初探与MediaPlayer(3)
- Hadoop集群最迅速的配置免密码登陆方法
- 开启和关闭按钮闪烁效果代码
- PHP学习笔记4(运算符)