2012-03-09 3 views
4

私はJavascriptを使用してチタンでアプリケーションを開発しています。私はencodeURIComponentのオープンソースの実装がJavascriptで必要です。encodeURIComponentアルゴリズムのソースコード

誰か私を案内したり、私にいくつかの実装を表示できますか?

+1

Mozillaの 'str_encodeURI_Component'の実装は" /js/src/jsstr.cpp "にあります:[http://mxr.mozilla.org/mozilla-central/source/js/src/jsstr.cpp]( http://mxr.mozilla.org/mozilla-central/source/js/src/jsstr.cpp)または[http://hg.mozilla.org/mozilla-central/file/](http://hg。 mozilla.org/mozilla-central/file/)。 – XP1

+0

@ XP1 MozillaはMXRを廃止しました。そのページは現在https://dxr.mozilla.org/mozilla-central/source/js/src/jsstr.cppにあります –

答えて

5

V8の実装はsrc/uri.jsのライン327で利用可能であり、BSDライセンスの下で配布されています。

// ECMA-262 - 15.1.3.4 
function URIEncodeComponent(component) { 
    var unescapePredicate = function(cc) { 
    if (isAlphaNumeric(cc)) return true; 
    // ! 
    if (cc == 33) return true; 
    // '()* 
    if (39 <= cc && cc <= 42) return true; 
    // -. 
    if (45 <= cc && cc <= 46) return true; 
    // _ 
    if (cc == 95) return true; 
    // ~ 
    if (cc == 126) return true; 

    return false; 
    }; 

    var string = ToString(component); 
    return Encode(string, unescapePredicate); 
} 

それはそこencodeURIComponentと呼ばれていないが、同じファイルにこのコードでは、マッピングをesablishes:この機能のための

InstallFunctions(global, DONT_ENUM, $Array(
    "escape", URIEscape, 
    "unescape", URIUnescape, 
    "decodeURI", URIDecode, 
    "decodeURIComponent", URIDecodeComponent, 
    "encodeURI", URIEncode, 
    "encodeURIComponent", URIEncodeComponent 
)); 

仕様は15.1.3.4です。

+0

しかし、あなたはEncodeを呼び出しています。私はすべてのプレーンJavaScript – Altaf

+0

@Altafを呼び出しています。 'Encode'は同じファイルに定義されています。 –

関連する問題