urlencode-as3

Created: 2012-03-24 17:52
Updated: 2014-04-07 06:20

README.md

urlencode-as3

Actionscript library to handle percent encoding/decoding.

Description

I often encounter a situation where percent encoding is done in the charset other than UTF-8 ouside of actionscript(especially at server side), and built-in methods like escape/unescape or escapeMultiByte/unecapeMutliByte doesn't help since they only support UTF-8 or charset specified in System.useCodePage.

Usage

import urlencode.URIString;

public function doSomething():void{

    var reqUrl:String="http://example.com?msg=%93%FA%96%7B%8C%EA";
    var aryParams:Array = reqUrl.replace(/.*\?(.*)/,"$1").split("&");
    var params:Object = {};

    for(var i:int=0;i < aryParams.length;i++){
        var key:String = aryParams[i].split("=")[0];
        var val:String = aryParams[i].split("=")[1];
        params[key]= val;
    }
    trace(params["msg"]); // "%93%FA%96%7B%8C%EA"

    var decoder:URIString = new URIString(params["msg"]);
    trace(decoder.decode(URIString.SHIFT_JIS)); // "日本語"

}

TODO

  • Add escape(encode) function(Only SHIFT_JIS unescaping has been implemented so far...).
  • Add charsets support other than SHIFT_JIS.
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more