2015-04-02 20:32:22 +00:00
|
|
|
var current_codepage = 1200, current_cptable;
|
2017-03-12 18:02:43 +00:00
|
|
|
/*:: declare var cptable:any; */
|
2014-05-03 18:51:10 +00:00
|
|
|
if(typeof module !== "undefined" && typeof require !== 'undefined') {
|
2017-03-05 00:56:31 +00:00
|
|
|
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel.js');
|
2014-05-03 18:51:10 +00:00
|
|
|
current_cptable = cptable[current_codepage];
|
|
|
|
}
|
2015-04-02 20:32:22 +00:00
|
|
|
function reset_cp() { set_cp(1200); }
|
2014-07-28 13:22:32 +00:00
|
|
|
var set_cp = function(cp) { current_codepage = cp; };
|
2014-05-03 18:51:10 +00:00
|
|
|
|
2014-07-28 13:22:32 +00:00
|
|
|
function char_codes(data) { var o = []; for(var i = 0, len = data.length; i < len; ++i) o[i] = data.charCodeAt(i); return o; }
|
2017-02-24 10:33:01 +00:00
|
|
|
var debom = function(data/*:string*/)/*:string*/ {
|
|
|
|
var c1 = data.charCodeAt(0), c2 = data.charCodeAt(1);
|
|
|
|
if(c1 == 0xFF && c2 == 0xFE) return data.substr(2);
|
|
|
|
if(c1 == 0xFE && c2 == 0xFF) return data.substr(2);
|
|
|
|
if(c1 == 0xFEFF) return data.substr(1);
|
|
|
|
return data;
|
|
|
|
};
|
2014-07-28 13:22:32 +00:00
|
|
|
|
2015-04-02 20:32:22 +00:00
|
|
|
var _getchar = function _gc1(x) { return String.fromCharCode(x); };
|
2014-07-28 13:22:32 +00:00
|
|
|
if(typeof cptable !== 'undefined') {
|
|
|
|
set_cp = function(cp) { current_codepage = cp; current_cptable = cptable[cp]; };
|
2017-02-24 10:33:01 +00:00
|
|
|
debom = function(data) {
|
2014-05-22 12:16:51 +00:00
|
|
|
if(data.charCodeAt(0) === 0xFF && data.charCodeAt(1) === 0xFE) { return cptable.utils.decode(1200, char_codes(data.substr(2))); }
|
2014-07-28 13:22:32 +00:00
|
|
|
return data;
|
|
|
|
};
|
2015-04-02 20:32:22 +00:00
|
|
|
_getchar = function _gc2(x) {
|
|
|
|
if(current_codepage === 1200) return String.fromCharCode(x);
|
|
|
|
return cptable.utils.decode(current_codepage, [x&255,x>>8])[0];
|
|
|
|
};
|
2014-05-22 12:16:51 +00:00
|
|
|
}
|