OSDN Git Service

Fix the bug of X.NodeAnime.
[pettanr/clientJs.git] / 0.6.x / js / 01_core / 00_builtin.js
index 8a8f073..e483e4e 100644 (file)
@@ -140,79 +140,95 @@ Array.prototype.indexOf || (Array.prototype.indexOf = function( searchElement, f
  */\r
 \r
 /*\r
- * Window\r
+ * original:\r
  * by https://web.archive.org/web/20100413085309/http://nurucom-archives.hp.infoseek.co.jp/digital/trans-uri.html\r
  */\r
+var _builtin_skipEncodeURI = (function(){\r
+       var encodeURIComponentTarget = '!\'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~',\r
+               encodeURITarget = '#$&+,-/:;=?@',\r
+               obj = {}, i;\r
+       for( i = encodeURIComponentTarget.length; i; ){\r
+               obj[ encodeURIComponentTarget.charCodeAt( --i ) ] = 2;\r
+       };\r
+       for( i = encodeURITarget.length; i; ){\r
+               obj[ encodeURITarget.charCodeAt( --i ) ] = 1;\r
+       };\r
+       return obj;\r
+})();\r
 \r
-/*\r
- * //\r
-// TransURI (UTF-8): transURI.js (Ver.041211)\r
-//\r
-// Copyright (C) http://nurucom-archives.hp.infoseek.co.jp/digital/\r
-//\r
+// /[^!#$&-;=?-Z_a-z~]/g\r
+window[ 'encodeURI' ] || (window[ 'encodeURI' ] = function( x ){ return _builtin_encodeURI( x, 0 ); });\r
+// /[^!'-*.0-9A-Z_a-z~-]/g\r
+window[ 'encodeURIComponent' ] || (window[ 'encodeURIComponent' ] = function( x ){ return _builtin_encodeURI( x, 1 ); });\r
 \r
-EncodeURI=function(str){\r
-       return str.replace(/[^!#$&-;=?-Z_a-z~]/g,function(s){\r
-               var c=s.charCodeAt(0);\r
-               return (c<16?"%0"+c.toString(16):c<128?"%"+c.toString(16):c<2048?"%"+(c>>6|192).toString(16)+"%"+(c&63|128).toString(16):"%"+(c>>12|224).toString(16)+"%"+(c>>6&63|128).toString(16)+"%"+(c&63|128).toString(16)).toUpperCase()\r
-       })\r
+function _builtin_encodeURI( x, kind ){\r
+       var result = [],\r
+               skip   = _builtin_skipEncodeURI,\r
+               p      = '%',\r
+               i = 0, l, chr, c;\r
+       \r
+       x += '';\r
+       \r
+       for( l = x.length; i < l; ++i ){\r
+               if( !( kind < skip[ c = x.charCodeAt( i ) ] ) ){\r
+                       chr = (\r
+                               c < 16 ? '%0' + c.toString(16) :\r
+                               c < 128 ? p + c.toString(16) :\r
+                               c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :\r
+                               p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)\r
+                       ).toUpperCase();\r
+               } else {\r
+                       chr = x.charAt( i );\r
+               };\r
+               result[ i ] = chr;\r
+       };\r
+       \r
+       return result.join( '' );\r
 };\r
 \r
-EncodeURIComponent=function(str){\r
-       return str.replace(/[^!'-*.0-9A-Z_a-z~-]/g,function(s){\r
-               var c=s.charCodeAt(0);\r
-               return (c<16?'%0'+c.toString(16):c<128?'%'+c.toString(16):c<2048?'%'+(c>>6|192).toString(16)+'%'+(c&63|128).toString(16):'%'+(c>>12|224).toString(16)+'%'+(c>>6&63|128).toString(16)+'%'+(c&63|128).toString(16)).toUpperCase()\r
-       })\r
-};\r
 \r
-DecodeURI=function(str){\r
-       return str.replace(/%(E(0%[AB]|[1-CEF]%[89AB]|D%[89])[0-9A-F]|C[2-9A-F]|D[0-9A-F])%[89AB][0-9A-F]|%[0-7][0-9A-F]/ig,function(s){\r
-               var c=parseInt(s.substring(1),16);\r
-               return String.fromCharCode(c<128?c:c<224?(c&31)<<6|parseInt(s.substring(4),16)&63:((c&15)<<6|parseInt(s.substring(4),16)&63)<<6|parseInt(s.substring(7),16)&63)\r
-       })\r
+function _builtin_decodeURI( x ){\r
+       var result    = [],\r
+               toInt     = parseInt,\r
+               toChrCode = String.fromCharCode,\r
+               n = -1, i = 0, l, chr, decode, code, memory;\r
+       \r
+       x += '';\r
+       \r
+       for( l = x.length; i < l; ++i ){\r
+               if( decode ){\r
+                       code = toInt( x.substr( i, 2 ), 16 );\r
+                       ++i;                                    \r
+                       if( 127 < code ){\r
+                               if( 223 < code ){\r
+                                       memory = ( code & 15 ) << 12;\r
+                                       code = toInt( x.substr( i + 2, 2 ), 16 ) & 63; // 00%00%00\r
+                                       i += 3;\r
+                                       memory += code << 6;                                                    \r
+                               } else {\r
+                                       memory = ( code & 63 ) << 6;\r
+                               };\r
+                               code = toInt( x.substr( i + 2, 2 ), 16 ) & 63;\r
+                               i += 3;\r
+                               code += memory;\r
+                       };\r
+                       // if( code !== code ) error\r
+                       //console.log( code );\r
+                       result[ ++n ] = toChrCode( code );\r
+                       decode = false;\r
+               } else {\r
+                       chr = x.charAt( i );\r
+                       if( !( decode = chr === '%' ) ){\r
+                               result[ ++n ] = chr;                    \r
+                       };\r
+               };\r
+       };\r
+       \r
+       return result.join( '' );\r
 };\r
- */\r
 \r
-/* 正規表現が使われているため、まだ投入しない itozyun\r
-window.encodeURI || (window.encodeURI = function (x) {\r
-       return ("" + x).replace(/[^!#$&-;=?-Z_a-z~]/g, function (s) {\r
-               var c = s.charCodeAt(0), p = "%";\r
-               return (\r
-                       c < 16 ? "%0" + c.toString(16) :\r
-                       c < 128 ? p + c.toString(16) :\r
-                       c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :\r
-                       p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)\r
-               ).toUpperCase();\r
-       });\r
-});\r
-\r
-window.encodeURIComponent || (window.encodeURIComponent = function (x) {\r
-       return ("" + x).replace(/[^!'-*.0-9A-Z_a-z~-]/g, function (s) {\r
-               var c = s.charCodeAt(0), p = "%";\r
-               return (\r
-                       c < 16 ? "%0" + c.toString(16) :\r
-                       c < 128 ? p + c.toString(16) :\r
-                       c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :\r
-                       p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)\r
-               ).toUpperCase();\r
-       });\r
-});\r
-\r
-// 手抜き\r
-window.decodeURI || (window.decodeURI = function (x) {\r
-       return ("" + x).replace(/%(E(0%[AB]|[1-CEF]%[89AB]|D%[89])[0-9A-F]|C[2-9A-F]|D[0-9A-F])%[89AB][0-9A-F]|%[0-7][0-9A-F]/ig, function (s) {\r
-               var c = parseInt(s.substring(1), 16);\r
-               return String.fromCharCode(\r
-                       c < 128 ? c :\r
-                       c < 224 ? (c & 31) << 6 | parseInt(s.substring(4), 16) & 63 :\r
-                       ((c & 15) << 6 | parseInt(s.substring(4), 16) & 63) << 6 | parseInt(s.substring(7), 16) & 63\r
-               );\r
-       });\r
-});\r
-*/\r
-\r
-\r
-//window.decodeURIComponent || (window.decodeURIComponent = window.decodeURI);\r
+window[ 'decodeURI' ] || (window[ 'decodeURI' ] = _builtin_decodeURI);\r
+window[ 'decodeURIComponent' ] || (window[ 'decodeURIComponent' ] = window.decodeURI);\r
 \r
 \r
 /*\r
@@ -258,82 +274,3 @@ if (window.ActiveXObject ? !Number.prototype.toFixed : (!navigator.taintEnabled
                };\r
        })(); */\r
        \r
-/*\r
- * Safari の JavaScript の不備 \r
- * http://nanto.asablo.jp/blog/2006/01/13/209495\r
- * \r
- * web.paulownia.jp - JavaScriptとクロージャ\r
- * https://web.archive.org/web/20070526063400/http://web.paulownia.jp/script/oop/closure.html\r
- * MacOSX 10.3のsafariにはhasOwnPropertyが実装されていないので、独自に追加する必要があります。\r
- * \r
- * prototype汚染問題でhasOwnPropertyを使わないクロスブラウザな方法\r
- * http://os0x.hatenablog.com/entry/20080901/1220272509\r
- */\r
-/*\r
-Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){\r
-               var proto = this.constructor && this.constructor.prototype,\r
-                       __p__ = proto && proto.__proto__,\r
-                       v     = this[ p ],\r
-                       r     = false;\r
-               \r
-               if( __p__ ) proto.__proto__ = null;\r
-               \r
-               if( p in this ){\r
-                       if( v !== v ){\r
-                               if( proto && ( p in proto ) && proto[ p ] !== proto[ p ] ){ // proto[ p ] is NaN\r
-                                       proto[ p ] = 0; // different value\r
-                                       r = this[ p ] !== this[ p ]; // isNaN?\r
-                                       proto[ p ] = v; // set NaN\r
-                               } else {\r
-                                       r = true;\r
-                               };\r
-                       } else\r
-                       if( proto && p in proto && proto[ p ] === v ){\r
-                               // this と proto に同名で同値が書かれている可能性あり\r
-                               proto[ p ] = v + ' '; // different value\r
-                               r = v === this[ p ];\r
-                               proto[ p ] = v;\r
-                       } else {\r
-                               r = true;\r
-                       };\r
-               };\r
-               \r
-               if( __p__ ) proto.__proto__ = __p__;\r
-               \r
-               return r;\r
-  }); */\r
-/*\r
-Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){\r
-               var proto = this.constructor && this.constructor.prototype,\r
-                       __p__ = proto && proto.__proto__,\r
-                       r     = false,//!!( __p__ && ( proto.__proto__ = null ) )\r
-                       _pro_, v, isNaN;\r
-               \r
-               if( __p__ ) proto.__proto__ = null;\r
-               if( this.__proto__ ){\r
-                       _pro_ = this.__proto__;\r
-                       this.__proto__ = null;\r
-               };\r
-               \r
-               if( p === '__proto__' ){\r
-                       r = !!_pro_;\r
-               } else {\r
-                       v     = this[ p ];\r
-                       isNaN = v !== v;                \r
-                       \r
-                       if( p in this ){\r
-                               if( proto && p in proto && ( proto[ p ] === v ) ^ isNaN ){ //true + false, false + true\r
-                                       // this と proto に同名で同値が書かれている可能性あり\r
-                                       proto[ p ] = v + ' '; // different value\r
-                                       r = ( v === this[ p ] ) ^ isNaN; // true + false, false + true\r
-                                       proto[ p ] = v;\r
-                               } else {\r
-                                       r = true;\r
-                               };\r
-                       };                      \r
-               };\r
-\r
-               if( __p__ ) proto.__proto__ = __p__;\r
-               if( _p_ ) this.__proto__ = _pro_;\r
-               return r;\r
-  }); */
\ No newline at end of file