?? utf8tounicode.c
字號:
/* 文 件 名:Utf8ToUnicode.c 作 者:丁宏偉 創建時間:2008年10月 修改時間:2008年11月26日*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include "gsm.h"int utf8_to_unicode(char *unicode,char *utf8,int n){ char buf[3]={0}; char buf1[3]={0}; char utf81[256]={0}; int i,j=0,k=0; int byte1=128; //1 byte 1000 0000; int value1=0; int byte2=224; //2 byte 1110 0000用于與utf8[i]與保留前4位; int value2=192; int byte3=240; //3 byte 1111 0000; int value3=224; if(n>128) n=128; for(i=0;i<n;i++){ if((utf8[i]&byte1) == value1){ unicode[j]='0'; unicode[++j]='0'; memset(buf,0,3); itoa(utf8[i],buf,3); unicode[++j]=buf[0]; unicode[++j]=buf[1]; j++; memset(buf,0,3); memset(buf1,0,3); } if((utf8[i]&byte2) == value2){//判斷是否是兩個字節 memset(buf,0,3); memset(buf1,0,3); buf[0]=(utf8[i]&0x1f)<<3; buf[0]=((utf8[++i]&0x3f)<<2)>>5; itoa(buf[0],buf1,3); unicode[j]=buf1[0]; unicode[++j]=buf1[1]; buf[1]=((utf8[++i]&0x3f)<<5); itoa(buf[1],buf1,3); // sprintf(buf1,"%x",buf[0]); unicode[++j]=buf1[0]; unicode[++j]=buf1[1]; // sprintf(buf1,"%x",buf[1]); j++; memset(buf,0,3); memset(buf1,0,3); } if((utf8[i] & byte3) == value3){ buf[0]=(utf8[i] & 0x1f)<<4; buf[0]|=((utf8[++i]&0x3f)<<2)>>4; itoa(buf[0],buf1,3); unicode[j]=buf1[0]; unicode[++j]=buf1[1]; buf[1]|=(utf8[i]&0x3f)<<6; buf[1]|=((utf8[++i]&0x3f)<<2)>>2; itoa(buf[1],buf1,3); unicode[++j]=buf1[0]; unicode[++j]=buf1[1]; j++; memset(buf,0,3); memset(buf1,0,3); } } if(j==0){ for(i=0;i<n;i++){ memset(buf,0,3); memset(buf1,0,3); itoa(utf8[i],buf,3); unicode[k++]=buf[0]; if(k==1) printf("unicode %c ",unicode[0]); else printf("unicode %c ",unicode[k]); unicode[k++]=buf[1]; printf("unicode %c ",unicode[k]); } j=k; } return j;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -