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

📄 gbunicode.java

📁 GB转换到UNICODE
💻 JAVA
字号:
package sun.police;
import java.io.*;
import java.util.Hashtable; 

public class GBUnicode
{ 
  byte high[]=new byte[6763],low[]=new byte[6763]; 
  char unichar[]=new char[6763]; 
  Hashtable UniGB; 

  public GBUnicode(String table_file)throws IOException 
  { 
    DataInputStream tables=new DataInputStream(new FileInputStream(table_file)); 

    int i,n=0;  
    byte b,bl,bh,num[]=new byte[20]; 

    UniGB=new Hashtable(7000,1); 
    while (n<2)
    { 
      do
      { 
        bh=(byte)tables.read(); 
      }while ((char)bh<=' '); //find first non-blank char 

      bl=(byte)tables.read(); 
      high[n]=bh; 
      low[n]=bl; 
      do{ 
        b=(byte)tables.read(); 
      }while (b!=(byte)':'); //find ':' 

      do
      { 
        b=(byte)tables.read(); 
      }while ((char)b<=' '); //find next non-blank char to reaas number 

      i=0; 
      while ((char)b>='0' && (char)b<='9')
      { 
        num[i++]=b; 
        b=(byte)tables.read(); 
     } 
      unichar[n]=(char)Integer.parseInt(new String(num,0,0,i)); 

     if (UniGB.get(new Character(unichar[n]))!= null) 
        System.out.println("Duplicated : "+unichar[n]); 
     UniGB.put(new Character(unichar[n]),new Integer(n));
     System.out.println(unichar[n]+" "+high[n]+" "+low[n]);  
      n=n+1; 
    } 
    tables.close(); 
  } 


  private int getGBindex(byte high,byte low)
  { 
    int i,j; 
    i=high-(byte)0xb0; 
    j=low-(byte)0xa1; 
    if (i <39) 
    {
      // L1 Chinese 
      if (j<0 || j>94) 
        return -1; 
      return (i*94+j); 
    } 
    else if (i==39) 
    {
      //one of the last 89 L1 Chinese 
      if (j<0 || j>89) 
        return -1; 
      return (i*94+j); 
    } 
    else 
    {
      //L2 Chinese 
      if (j<0 || j>94) 
        return -1; 
      return (i*94+j-5); 
    } 
  } 

  public byte[] Uni2GB(char unicode) 
  { 

    Integer index=(Integer)UniGB.get(new Character(unicode)); 
    if (index==null) 
      return null; 
    byte ch[]=new byte[2]; 
    ch[0]=high[index.intValue()]; 
    ch[1]=low[index.intValue()]; 
    return ch; 
  } 

  public char GB2Uni(byte high, byte low) 
  { 
    int index=getGBindex(high,low); 
    if (index ==-1) //not GB Chinese 
       return 0; 
    return(unichar[index]); 
  } 
  
  public String int2hexstr(int val) 
  { 
	String str1 = "", str2 = "", cstr = ""; 
	int c1, c2; 

	c1 = val / 16; 
	c2 = val % 16; 
	str1 = hex2str(c1); 
	str2 = hex2str(c2); 
	cstr = str1 + str2; 
	return cstr; 
   } 

   public String hex2str(int hexint) 
   { 
	String hexchar = ""; 
	switch(hexint)
	 { 
		case 0: 
		case 1: 
		case 2: 
		case 3: 
		case 4: 
		case 5: 
		case 6: 
		case 7: 	
		case 8: 
		case 9: 
				hexchar = Integer.toString(hexint); 
				break; 
		case 10: 
				hexchar = "A"; 
				break; 
		case 11: 
				hexchar = "B"; 
				break; 
		case 12: 
				hexchar = "C"; 
				break; 
		case 13: 
				hexchar = "D"; 
				break; 
		case 14: 
				hexchar = "E"; 
				break; 
		case 15: 
				hexchar = "F"; 
				break; 
		} 
		return hexchar; 
	} 

  
  	public static void main(String[] args)
	{	
		byte b[]=new byte[2];
		
		try
		{
			GBUnicode conversion=new GBUnicode("c.txt");
			
			System.out.println('\u91d1');
			System.out.println('\u9633');
			System.out.println('\u03d1');
		}
		catch(Exception e){e.printStackTrace();}
	}
} 

⌨️ 快捷键说明

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