Site Search :
Standard Enterprise XML Methodology Pattern Setting Tunning Other
Article Contributors
GuestBook
Javapattern Maven
XSourceGen Dev
JetSpeed Test
JLook Image
jLook Family Site


Extract unicode from ASCII format text
 
À¯´ÏÄڵ带 ÀÌ¿ëÇÏ¿© ÇØ´ç ½ºÆ®¸µÀÇ °ªÀ» ÃßÃâÇÏ¿©, encoding ÀÛ¾÷°ú decodindÀÛ¾÷À» Çϵµ·Ï ÇÑ´Ù. º¸Åë jad·Î decompileÇÒ°æ¿ì ƯÁ¤charset¿¡ ´ëÇÏ¿© \uXXXX°¡ ºÙ°ÔµÈ´Ù. more.. ( 2003/02/28 ) 95
Written by ienvyou - ÃÖÁö¿õ
1 of 1
 
<font face='±¼¸²'>¿ì¼± ¿Ö ÀÌ·± Äڵ带 ÀÛ¼ºÇß´ÂÁö »ý°¢ÇØ º¼¼ö ÀÖ´Ù. ¾ðÁ¨°¡ ÀÌ·¯ÇÑ Áú¹®ÀÌ
µé¾î¿ÂÀûÀÌ ÀÖ´Ù. Decompiler¸¦ ÀÌ¿ëÇÏ¿© ÀÛ¼ºµÈ ÆÄÀÏ¿¡ ÇѱÛÄڵ尡 \uXXXXÇüÅ·Π
µé¾î°¡ÀÖ´Â °ÍÀ» º¸°Ô µÈ´Ù. ÀÌ·²¶§ ÁÖ¼®À̳ª ¾î¶² ÄÚµåµéÀ» È®ÀÎÇÒ¼ö ¾ø±â ¶§¹®¿¡
ÇØ´ç Unicode¸¦ Çѱ۷Π´Ù½Ã ¹Ù²Ü¼ö ÀÖ´Â ¹æ¹ýÀÌ ¾ø´À³Ä¿¡ °üÇÑ °ÍÀ̾ú´Ù.

www.unicode.org¿¡ °¡¸é ÇØ´ç codeset¿¡ ´ëÇÑ Æ¯Â¡ ¹× °¢ ³ª¶óÀÇ ¾ð¾î¿¡ ´ëÇÑ unicode¸¦
¹Þ¾Æ¼­ ¼³Ä¡ÇÒ¼ö ÀÖ´Â ÆÄÀϵéÀ» Á¦°øÇÏ°í ÀÖ´Ù.

ÀÌ·¯ÇÑ À¯´ÏÄÚµå·Î´Â ¸ðµç ³ª¶óÀÇ ¾ð¾î¸¦ Ç¥ÇöÇÒ¼ö ÀÖÀ¸¸ç, ¶ÇÇÑ ³»¿ë¶ÇÇÑ ±¤¹üÀ§ÇϹǷÎ
Á¡Â÷ ¸¹Àº º¥´õµéÀÌ »ç¿ëÇÏ°í ÀÖÁö¸¸, ¾ÆÁ÷±îÁö ´ë´Ù¼ö°¡ ¾²´Â ¹ü¿ëÄÚµå ÇüÅ°¡ ¾Æ´Ï´Ù.

¿ì¼± ÇÁ·Î±×·¥À» º»ÈÄ À̾߱â ÇÏÀÚ.
¾Æ·¡ÀÇ ÇÁ·Î±×·¥Àº °£´ÜÇÏ°Ô \uXXXX°¡ Æ÷ÇÔµÈ Äڵ带 ã´Â Ŭ·¡½ºÆÄÀÏÀÌ´Ù.

import java.util.*;
import java.io.*;
class  UnicodeToHangul {
public static void main(String[] args) throws Exception{
    BufferedReader br = new BufferedReader(new FileReader("SQLArrayTest.jad"));
    String str = null;
    StringBuffer sb = new StringBuffer(1000);
    while( (str = br.readLine()) != null) {
	sb.append(str + "\n");
    }


    String unicode = "";
    for(int i = 0 ; i < sb.length() ; i++){
	int c = sb.charAt(i);
	//if(Character.isUnicodeIdentifierPart(c))	System.out.print(c + "/");
	if(c == 92) {
	    for(int j = 0 ; j < 6 ; j++){
		unicode += sb.charAt(i++);
	    }
	    System.out.println("unicode find : " + unicode);
	    unicode="";
	}
	
    }
    //System.out.println(sb.toString());

    Unicoder uni  = new Unicoder();
    System.out.println(uni.decode(sb.toString()));

    
    
    br.close();
}
}

Å×½ºÆ®´Â ¿ªÄÄÆÄÀÏµÈ jadÆÄÀÏÀ» ÀÌ¿ëÇßÀ¸¸ç, ±×¾È¿¡ ¾î¶² Äڵ尡 µé¾î°¡ ÀÖ´ÂÁö 
È®ÀÎÇϱâ À§ÇÔÀ̾ú´Ù. ±× ÆÄÀÏÀ» º¸°Ô µÇ¸é 

    System.out.println("\uD589 " + i + " : ");
    ARRAY array = ((OracleResultSet)resultset).getARRAY(1);
    System.out.println("\uBC30\uC5F4\uD0C0\uC785 " + array.getSQLTypeName());

ó·³ ÇѱۺκÐÀÌ \uBC30ó·³ ³ªÅ¸³­´Ù´Â °ÍÀ» º¼¼ö ÀÖ´Ù.

»ç½Ç ¸ðµç javaÆÄÀÏÀ» ÀÌ¿ëÇÏ¿© charAt()¸Þ¼Òµå¸¦ ÀÌ¿ëÇÏ¿© ¿µ¹®ÀÚ¸¦ È®ÀÎÇغ¸¸é °á±¹ 
\u0030ÀÇ ÇüÅ·Π³ªÅ¸³ª°Ô µÈ´Ù. 
À¯´ÏÄÚµå´Â ¾ÕÀÇ charset 127°³ºÎºÐÀ» ASCIIÇüÅ·ΠÆ÷ÇÔ½ÃÄÑ »ç¿ëÇÏ°í ÀÖ´Ù.

public static String encode( String ascii){
  StringBuffer uniString = new StringBuffer();
  String tempString = null;
  for( int i=0 ; i < ascii.length() ; i++){
	tempString = Integer.toHexString( ascii.charAt(i) );
	uniString.append( 
	"\\u"+(tempString.length()==4 ? tempString : "00" + tempString ) );
  }
  return uniString.toString();
}
public static String decode( String unicode){
  StringBuffer str = new StringBuffer();
    for( int i= unicode.indexOf("\\u") ; i > -1 ; i = unicode.indexOf("\\u") ){
	System.out.print("  " + i);
	str.append( unicode.substring( 0, i ) );
	str.append( 
	   String.valueOf( (char)Integer.parseInt( unicode.substring( i + 2, i + 6 ) ,16) ) 
	);
	unicode = unicode.substring( i +6);
    }
    str.append( unicode );
    return str.toString();
}

µû¶ó¼­ ¿µ¹®ÀÚÀÇ °æ¿ì 127°³ÀÇ asciiÀÇ ¾È¿¡ Àֱ⶧¹®¿¡ charAt()À¸·Î 
º¯È¯½ÃŲ ¹®ÀÚ°¡ 4bit + 4bit, Áï 8bitÇüÅ·Π³ª¿À°Ô µÇ´Âµ¥ 2byteü°èÀÇ unicode¿¡¼­´Â ¾ÕºÎºÐÀÇ
³»¿ëÀ» 00À¸·Î ä¿ì°Ô µÈ´Ù.
À§ÀÇ encode¸Þ¼Òµå°¡ ±×·¯ÇÑ ¿ªÇÒÀ» ÇØÁÖ¸ç, decodeÀÇ °æ¿ì ÇØ´ç ½ºÆ®¸µÀÇ °ª¿¡ ´ëÇÏ¿©
\\u·Î¼­ escape character¸¦ ã¾Æ³½ÈÄ ÀÌÈÄ unicode.substring( i + 2, i + 6 )·Î \u±îÁöÀÇ 
³»¿ëÀ» ÀÚ¸¥ÈÄ radix 16À» ÃëÇÏ¿© ¹Ù²Ù°Ô µÇ¸é ´Ù½Ã ¿ø·¡ÀÇ ¹®ÀÚµé·Î º¯È¯ÀÌ µÇ°Ô µÈ´Ù.
¸ðµç ü°è¸¦ ÀÏÁ¤ÇÑ ±ÔÄ¢À» °¡Áö°í ÀÖÀ¸¸ç ±×·¯ÇÑ ¹æ¹ýÀ» ¾Ë°Ô µÇ¸é ¾Ë°í¸®ÁòÀ¸·Î
ÇØ°áÇØ ³¾¼ö ÀÖ´Â ³»¿ëµéÀÌ ¸¹´Ù..


 
1
References
 
http://www.unicode.org
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD