示例#1
0
void Util_GBK2Unicode(u8 *src,u8 *dst)
{
  OS_CPU_SR cpu_sr = 0;
	u16 temp; 
	u8 buf[2];
	
	OS_ENTER_CRITICAL();// 进入临界区(无法被中断打断)  

	while(*src!=0)
	{
		if(*src<0X81)	// 非汉字
		{
			temp=(u16)ff_convert((WCHAR)*src,1);
			src++;
		}
		else 			// 汉字,占2个字节
		{
			buf[1]=*src++;
			buf[0]=*src++;    
			temp=(u16)ff_convert((WCHAR)*(u16*)buf,1); 
		}
		*dst++=Util_Hex2Chr((temp>>12)&0X0F);
		*dst++=Util_Hex2Chr((temp>>8)&0X0F);
		*dst++=Util_Hex2Chr((temp>>4)&0X0F);
		*dst++=Util_Hex2Chr(temp&0X0F);
	}

	*dst = 0;// 添加结束符
	
	OS_EXIT_CRITICAL();	// 退出临界区(可以被中断打断)	
}
示例#2
0
static void gbk_to_unicode(rt_uint16_t *unicode, const unsigned char *text, int len)
{
	int i;
	unsigned short wch;
	extern unsigned short ff_convert(unsigned short wch, int direction);

	for (i = 0; i < len; )
	{
		if (*text < 0x80)
		{
			wch = *text;
			*unicode = ff_convert(wch, 1);
			text ++;
			i ++;
		}
		else
		{
			wch = wch = *(text + 1) | (*text << 8);
			*unicode = ff_convert(wch, 1);
			text += 2;
			i += 2;
		}

		unicode ++;
	}

	*unicode = '\0';
}
示例#3
0
void Util_Unicode2GBK(u8 *src, u8 *dst)
{
  OS_CPU_SR cpu_sr = 0;
	u16 temp; 
	u8 buf[2];
	
	OS_ENTER_CRITICAL();//进入临界区(无法被中断打断)  
	
	while(*src!=0)
	{
		buf[1]=Util_Chr2Hex(*src++)*16;
		buf[1]+=Util_Chr2Hex(*src++);
		buf[0]=Util_Chr2Hex(*src++)*16;
		buf[0]+=Util_Chr2Hex(*src++);
		temp=(u16)ff_convert((WCHAR)*(u16*)buf,0);
		if(temp<0X80){*dst=temp;dst++;}
		else {*(u16*)dst=SWAP16(temp);dst+=2;}
	}		
	*dst = 0;//添加结束符
	
	OS_EXIT_CRITICAL();	// 退出临界区(可以被中断打断)	
}