From c0e79d3d794e822ff86fd784efaa406df3b8c3dd Mon Sep 17 00:00:00 2001 From: cjy37 Date: Fri, 20 May 2016 20:16:40 +0800 Subject: [PATCH 1/2] Update jquery.base64.js --- jquery.base64.js | 170 +++++++++++++++++++++-------------------------- 1 file changed, 77 insertions(+), 93 deletions(-) diff --git a/jquery.base64.js b/jquery.base64.js index 6c98f156..d3024520 100644 --- a/jquery.base64.js +++ b/jquery.base64.js @@ -1,68 +1,8 @@ -/*jslint adsafe: false, bitwise: true, browser: true, cap: false, css: false, - debug: false, devel: true, eqeqeq: true, es5: false, evil: false, - forin: false, fragment: false, immed: true, laxbreak: false, newcap: true, - nomen: false, on: false, onevar: true, passfail: false, plusplus: true, - regexp: false, rhino: true, safe: false, strict: false, sub: false, - undef: true, white: false, widget: false, windows: false */ -/*global jQuery: false, window: false */ -//"use strict"; - -/* - * Original code (c) 2010 Nick Galbreath - * http://code.google.com/p/stringencoders/source/browse/#svn/trunk/javascript - * - * jQuery port (c) 2010 Carlo Zottmann - * http://github.com/carlo/jquery-base64 - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. -*/ - -/* base64 encode/decode compatible with window.btoa/atob - * - * window.atob/btoa is a Firefox extension to convert binary data (the "b") - * to base64 (ascii, the "a"). - * - * It is also found in Safari and Chrome. It is not available in IE. - * - * if (!window.btoa) window.btoa = $.base64.encode - * if (!window.atob) window.atob = $.base64.decode - * - * The original spec's for atob/btoa are a bit lacking - * https://developer.mozilla.org/en/DOM/window.atob - * https://developer.mozilla.org/en/DOM/window.btoa - * - * window.btoa and $.base64.encode takes a string where charCodeAt is [0,255] - * If any character is not [0,255], then an exception is thrown. - * - * window.atob and $.base64.decode take a base64-encoded string - * If the input length is not a multiple of 4, or contains invalid characters - * then an exception is thrown. - */ - jQuery.base64 = ( function( $ ) { var _PADCHAR = "=", _ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", - _VERSION = "1.0"; + _VERSION = "1.1";//Mr. Ruan fix to 1.1 to support asian char(utf8) function _getbyte64( s, i ) { @@ -79,13 +19,34 @@ jQuery.base64 = ( function( $ ) { return idx; } + function _decode_chars(y, x){ + while(y.length > 0){ + var ch = y[0]; + if(ch < 0x80) { + y.shift(); + x.push(String.fromCharCode(ch)); + }else if((ch & 0x80) == 0xc0){ + if(y.length < 2) break; + ch = y.shift(); + var ch1 = y.shift(); + x.push(String.fromCharCode( ((ch & 0x1f) << 6) + (ch1 & 0x3f))); + }else{ + if(y.length < 3) break; + ch = y.shift(); + var ch1 = y.shift(); + var ch2 = y.shift(); + x.push(String.fromCharCode(((ch & 0x0f) << 12) + ((ch1 & 0x3f) << 6) + (ch2 & 0x3f))); + } + } + } function _decode( s ) { var pads = 0, i, b10, imax = s.length, - x = []; + x = [], + y = []; s = String( s ); @@ -109,69 +70,93 @@ jQuery.base64 = ( function( $ ) { } for ( i = 0; i < imax; i += 4 ) { + var ch1 = _getbyte64( s, i ); + var ch2 = _getbyte64( s, i + 1); + var ch3 = _getbyte64( s, i + 2); + var ch4 = _getbyte64( s, i + 3); + b10 = ( _getbyte64( s, i ) << 18 ) | ( _getbyte64( s, i + 1 ) << 12 ) | ( _getbyte64( s, i + 2 ) << 6 ) | _getbyte64( s, i + 3 ); - x.push( String.fromCharCode( b10 >> 16, ( b10 >> 8 ) & 0xff, b10 & 0xff ) ); + y.push(b10 >> 16); + y.push((b10 >> 8) & 0xff); + y.push(b10 & 0xff); + _decode_chars(y, x); } - switch ( pads ) { case 1: b10 = ( _getbyte64( s, i ) << 18 ) | ( _getbyte64( s, i + 1 ) << 12 ) | ( _getbyte64( s, i + 2 ) << 6 ); - x.push( String.fromCharCode( b10 >> 16, ( b10 >> 8 ) & 0xff ) ); + y.push(b10 >> 16); + y.push((b10 >> 8) & 0xff); break; case 2: b10 = ( _getbyte64( s, i ) << 18) | ( _getbyte64( s, i + 1 ) << 12 ); - x.push( String.fromCharCode( b10 >> 16 ) ); + y.push(b10 >> 16); break; } - + _decode_chars(y, x); + if(y.length > 0) throw "Cannot decode base64"; return x.join( "" ); } - function _getbyte( s, i ) { - var x = s.charCodeAt( i ); - - if ( x > 255 ) { - throw "INVALID_CHARACTER_ERR: DOM Exception 5"; + function _get_chars(ch, y){ + if(ch < 0x80) y.push(ch); + else if(ch < 0x800){ + y.push(0xc0 + ((ch >> 6) & 0x1f)); + y.push(0x80 + (ch & 0x3f)); + }else{ + y.push(0xe0 + ((ch >> 12) & 0xf)); + y.push(0x80 + ((ch >> 6) & 0x3f)); + y.push(0x80 + (ch & 0x3f)); } - - return x; } - - + + + function _encode( s ) { if ( arguments.length !== 1 ) { throw "SyntaxError: exactly one argument required"; } s = String( s ); - - var i, - b10, - x = [], - imax = s.length - s.length % 3; - if ( s.length === 0 ) { return s; } - - for ( i = 0; i < imax; i += 3 ) { - b10 = ( _getbyte( s, i ) << 16 ) | ( _getbyte( s, i + 1 ) << 8 ) | _getbyte( s, i + 2 ); - x.push( _ALPHA.charAt( b10 >> 18 ) ); - x.push( _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) ); - x.push( _ALPHA.charAt( ( b10 >> 6 ) & 0x3f ) ); - x.push( _ALPHA.charAt( b10 & 0x3f ) ); + + //s = _encode_utf8(s); + var i, + b10, + y = [], + x = [], + len = s.length; + i = 0; + while(i < len){ + _get_chars(s.charCodeAt(i), y); + while(y.length >= 3){ + var ch1 = y.shift(); + var ch2 = y.shift(); + var ch3 = y.shift(); + b10 = ( ch1 << 16 ) | ( ch2 << 8 ) | ch3; + x.push( _ALPHA.charAt( b10 >> 18 ) ); + x.push( _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) ); + x.push( _ALPHA.charAt( ( b10 >> 6 ) & 0x3f ) ); + x.push( _ALPHA.charAt( b10 & 0x3f ) ); + } + i++; } + - switch ( s.length - imax ) { + switch ( y.length ) { case 1: - b10 = _getbyte( s, i ) << 16; + var ch = y.shift(); + b10 = ch << 16; x.push( _ALPHA.charAt( b10 >> 18 ) + _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) + _PADCHAR + _PADCHAR ); break; case 2: - b10 = ( _getbyte( s, i ) << 16 ) | ( _getbyte( s, i + 1 ) << 8 ); + var ch1 = y.shift(); + var ch2 = y.shift(); + b10 = ( ch1 << 16 ) | ( ch2 << 8 ); x.push( _ALPHA.charAt( b10 >> 18 ) + _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) + _ALPHA.charAt( ( b10 >> 6 ) & 0x3f ) + _PADCHAR ); break; } @@ -187,4 +172,3 @@ jQuery.base64 = ( function( $ ) { }; }( jQuery ) ); - From 5bf4bae27b7c79eb97d0d91ad6bc22ecdcccb01f Mon Sep 17 00:00:00 2001 From: cjy37 Date: Fri, 20 May 2016 20:23:05 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3aa457db..7cd6c9e8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -tableExport.jquery.plugin +tableExport.jquery.plugin zh-CN =========================

Export HTML Table to