상세 컨텐츠

본문 제목

플래시 AS3.0 문자별 인코딩 관련

ADOBE/ ActionScript

by AlrepondTech 2012. 2. 23. 16:22

본문

반응형

 

 

 

 

=================================

=================================

=================================

 

 

 

 

 

 

 

출처: https://github.com/lyokato/as3jcode

as3jcode  I don't believe in ByteArray.readMultiByte/writeMultiByte  = Author  Lyo Kato, <lyo.kato@gmail.com>  = License  MIT-License  = Usage  import org.coderepos.text.encoding.Jcode;  var utf8Bytes:ByteArray = new ByteArray(); utf8Bytes.writeUTFBytes("にほんご");  // convert to EUC-JP byte code var eucBytes:ByteArray = Jcode.utf8_euc(utf8Bytes);  // convert to ISO-2022-JP byte code var jisBytes:ByteArray = Jcode.utf8_jis(utf8Bytes);  // convert to Shift_JIS byte code var jisBytes:ByteArray = Jcode.utf8_sjis(utf8Bytes);  // convert to UTF-16 byte code var utf16Bytes:ByteArray = Jcode.utf8_utf16(utf8Bytes);  // with BOM that represents Big Endian var utf16Bytes:ByteArray = Jcode.utf8_utf16be(utf8Bytes);  utf8Bytes  = Jcode.euc_utf8(eucBytes); utf8nBytes = Jcode.euc_utf8n(eucBytes); utf8Bytes  = Jcode.jis_utf8(jisBytes); utf8nBytes = Jcode.jis_utf8n(jisBytes); utf8Bytes  = Jcode.sjis_utf8(sjisBytes); utf8nBytes = Jcode.sjis_utf8n(sjisBytes);  utf8Bytes  = Jcode.utf16_utf8(sjisBytes); utf8nBytes = Jcode.utf16_utf8n(sjisBytes);  jisBytes  = Jcode.euc_jis(eucBytes); sjisBytes = Jcode.euc_sjis(eucBytes); eucBytes  = Jcode.jis_euc(jisBytes); sjisBytes = Jcode.jis_sjis(jisBytes); eucBytes  = Jcode.sjis_euc(sjisBytes); jisBytes  = Jcode.sjis_jis(sjisBytes);   ** Short circuit  *** Encoding from UTF-8 ActionScript native string  var utf8Bytes:ByteArray = new ByteArray(); utf8Bytes.writeUTFBytes("日本語"); var eucBytes:ByteArray = Jcode.utf8_euc(utf8Bytes);  instread of above 3 lines code, you can use to_xxx methods.  var eucBytes:ByteArray  = Jcode.to_euc("日本語"); var jisBytes:ByteArray  = Jcode.to_jis("日本語"); var sjisBytes:ByteArray = Jcode.to_sjis("日本語");  *** Decoding to UTF-8 ActionScript native string  var utf8String:String = Jcode.from_euc(eucBytes); var utf8String:String = Jcode.from_jis(jisBytes); var utf8String:String = Jcode.from_sjis(sjisBytes);  ** Katakana  Hankaku to Zenkaku  var utf8String:String = Jcode.h2z("アイウエオ"); // utf8String should be "アイウエオ".  var origin:String = Jcode.z2h(utf8String); // origin should be "アイウエオ";  ** Validation  if (Jcode.is_hiragana(utf8string)) {  }  if (Jcode.is_zenkaku_katakana(utf8string)) {  }  if (Jcode.is_hankaku_katakana(utf8string)) {  }  // zenkaku and hankaku katakana if (Jcode.is_katakana(utf8string)) {  }  = TODO  Zenkaku to Hankaku conversion (required?) Support UTF-16LE, UTF-32, (UTF-7) 

//-------------------------------------------------------------------

bytearray

flash.utils.ByteArray.readMultiByte(length:uint, charSet:String):String
Reads a multibyte string of specified length from the byte stream using the specified character set.
Parameters:
length The number of bytes from the byte stream to read.
charSet The string denoting the character set to use to interpret the bytes. Possible character set strings include "shift-jis", "cn-gb", "iso-8859-1", and others. For a complete list, see Supported Character Sets.

Note: If the value for the charSet parameter is not recognized by the current system, the application uses the system's default code page as the character set. For example, a value for the charSet parameter, as in myTest.readMultiByte(22, "iso-8859-01") that uses 01 instead of 1 might work on your development machine, but not on another machine. On the other machine, the application will use the system's default code page.

Returns:
UTF-8 encoded string.
Throws:
EOFError - There is not sufficient data available to read.
Language Version:
3.0
Player Version:
Flash 9, AIR 1.0

 

 

 

=================================

=================================

=================================

 

 

 

반응형


관련글 더보기

댓글 영역