私はJavascriptを使用してチタンでアプリケーションを開発しています。私はencodeURIComponent
のオープンソースの実装がJavascriptで必要です。encodeURIComponentアルゴリズムのソースコード
誰か私を案内したり、私にいくつかの実装を表示できますか?
私はJavascriptを使用してチタンでアプリケーションを開発しています。私はencodeURIComponent
のオープンソースの実装がJavascriptで必要です。encodeURIComponentアルゴリズムのソースコード
誰か私を案内したり、私にいくつかの実装を表示できますか?
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です。
しかし、あなたはEncodeを呼び出しています。私はすべてのプレーンJavaScript – Altaf
@Altafを呼び出しています。 'Encode'は同じファイルに定義されています。 –
encodeuricomponentが必要ですか?すでにJSに存在しています。
とにかく、ここでの実装例です:
JSの中にありますが、私はオープンソースをプロジェクトの一部にする必要があります。提供していません – Altaf
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
@ XP1 MozillaはMXRを廃止しました。そのページは現在https://dxr.mozilla.org/mozilla-central/source/js/src/jsstr.cppにあります –