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