⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utf8.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
字号:

/*
 * Convert ansi to utf-8 
 * it does not support more that utf-16 
 * the table we are using is base on utf-16 then we convert the table to utf-8
 * 
 * All table lookup the ansi char to utf-16 then we calc the utf-8 format. 
 */

#include "oem437.h"       /* windows oem 437 */     
#include "oem850.h"       /* windows oem 850 */  
#include "Windows28591.h" /* windows 28591 aka ISO-2859-1 (Latin 1) */
#include "Windows28592.h" /* windows 28592 aka ISO-2859-2 (Latin 2) */

int ansiCodePage(int codepage, unsigned char *inBuffer, unsigned char *outBuffer, int Lenght)
{
  int t;
  int ch;
  int pos=0;

  for (t=0;t<Lenght;t++)
  {
	  ch=-1;
	  if (codepage == 437)
	  {
		  ch = (int) table_OEM437[ ((unsigned char)inBuffer[t])]; 
	  }

	  if (codepage == 850)
	  {
		  ch = (int) table_OEM850[ ((unsigned char)inBuffer[t])]; 	     	  		  
	  }

	  if (codepage == 28591)
	  {
		  ch = (int) table_Windows28591[ ((unsigned char)inBuffer[t])]; 	     	  		  
	  }
	  if (codepage == 28592)
	  {
		  ch = (int) table_Windows28592[ ((unsigned char)inBuffer[t])]; 	     	  		  
	  }

	  


	  if (ch == -1)
	  {
	      break;
	  }

	  if (ch <= 0x7F)
	  {
		  outBuffer[pos]=ch;
		  pos++;
	  }
	  else if  (ch <=0x07FF) // 1 1111 11 1111
	  {		                               
         outBuffer[pos]= 0xC0  | (0x1F & (ch >> 6));	// 110x xxxx 
		 outBuffer[pos+1]= 0x80 | (0x3f & ch);  // 11xx xxxx   	 
		 pos+=2;
	  }

	  else if  (ch <=0xFFFF) // 11 11 11 11 11 11 11 11 
	  {		        
         outBuffer[pos]= 0xC2  | (0xf & (ch >> 12)); // 1110xxxx 
		 outBuffer[pos+1]= 0x80 | (0x3f & (ch >> 6));  // 10xxxxxx
		 outBuffer[pos+1]= 0x80 | (0x3f & ch);  // 10xxxxxx		                                            
		 pos+=3;
	  }

  }  
  
  return pos;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -