@datawrapper/jschardet 3.0.1-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTORS +4 -0
- package/LICENSE +504 -0
- package/README.md +101 -0
- package/dist/jschardet.js +7859 -0
- package/dist/jschardet.min.js +669 -0
- package/index.d.ts +13 -0
- package/index.js +1 -0
- package/package.json +33 -0
- package/src/big5freq.js +925 -0
- package/src/big5prober.js +54 -0
- package/src/chardistribution.js +301 -0
- package/src/charsetgroupprober.js +120 -0
- package/src/charsetprober.js +104 -0
- package/src/codingstatemachine.js +71 -0
- package/src/constants.js +40 -0
- package/src/escprober.js +109 -0
- package/src/escsm.js +250 -0
- package/src/eucjpprober.js +107 -0
- package/src/euckrfreq.js +597 -0
- package/src/euckrprober.js +54 -0
- package/src/euctwfreq.js +429 -0
- package/src/euctwprober.js +54 -0
- package/src/gb2312freq.js +473 -0
- package/src/gb2312prober.js +54 -0
- package/src/hebrewprober.js +323 -0
- package/src/index.js +56 -0
- package/src/jisfreq.js +569 -0
- package/src/jpcntx.js +242 -0
- package/src/langbulgarianmodel.js +228 -0
- package/src/langcyrillicmodel.js +329 -0
- package/src/langgreekmodel.js +225 -0
- package/src/langhebrewmodel.js +199 -0
- package/src/langhungarianmodel.js +225 -0
- package/src/langthaimodel.js +200 -0
- package/src/latin1prober.js +168 -0
- package/src/logger.js +7 -0
- package/src/mbcharsetprober.js +99 -0
- package/src/mbcsgroupprober.js +64 -0
- package/src/mbcssm/big5.js +52 -0
- package/src/mbcssm/eucjp.js +54 -0
- package/src/mbcssm/euckr.js +51 -0
- package/src/mbcssm/euctw.js +55 -0
- package/src/mbcssm/gb2312.js +60 -0
- package/src/mbcssm/sjis.js +54 -0
- package/src/mbcssm/ucs2be.js +56 -0
- package/src/mbcssm/ucs2le.js +56 -0
- package/src/mbcssm/utf8.js +75 -0
- package/src/sbcharsetprober.js +137 -0
- package/src/sbcsgroupprober.js +83 -0
- package/src/sjisprober.js +105 -0
- package/src/universaldetector.js +262 -0
- package/src/utf8prober.js +108 -0
package/src/escprober.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The Original Code is Mozilla Universal charset detector code.
|
|
3
|
+
*
|
|
4
|
+
* The Initial Developer of the Original Code is
|
|
5
|
+
* Netscape Communications Corporation.
|
|
6
|
+
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
7
|
+
* the Initial Developer. All Rights Reserved.
|
|
8
|
+
*
|
|
9
|
+
* Contributor(s):
|
|
10
|
+
* António Afonso (antonio.afonso gmail.com) - port to JavaScript
|
|
11
|
+
* Mark Pilgrim - port to Python
|
|
12
|
+
* Shy Shalom - original C code
|
|
13
|
+
*
|
|
14
|
+
* This library is free software; you can redistribute it and/or
|
|
15
|
+
* modify it under the terms of the GNU Lesser General Public
|
|
16
|
+
* License as published by the Free Software Foundation; either
|
|
17
|
+
* version 2.1 of the License, or (at your option) any later version.
|
|
18
|
+
*
|
|
19
|
+
* This library is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
22
|
+
* Lesser General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
25
|
+
* License along with this library; if not, write to the Free Software
|
|
26
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
27
|
+
* 02110-1301 USA
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
var CharSetProber = require('./charsetprober');
|
|
31
|
+
var CodingStateMachine = require('./codingstatemachine');
|
|
32
|
+
var escsm = require('./escsm');
|
|
33
|
+
var constants = require('./constants');
|
|
34
|
+
|
|
35
|
+
function EscCharSetProber() {
|
|
36
|
+
CharSetProber.apply(this);
|
|
37
|
+
|
|
38
|
+
var self = this;
|
|
39
|
+
|
|
40
|
+
function init() {
|
|
41
|
+
self._mCodingSM = [
|
|
42
|
+
new CodingStateMachine(escsm.HZSMModel),
|
|
43
|
+
new CodingStateMachine(escsm.ISO2022CNSMModel),
|
|
44
|
+
new CodingStateMachine(escsm.ISO2022JPSMModel),
|
|
45
|
+
new CodingStateMachine(escsm.ISO2022KRSMModel)
|
|
46
|
+
];
|
|
47
|
+
self._supportedCharsetNames = [];
|
|
48
|
+
for (const codingSM of self._mCodingSM) {
|
|
49
|
+
self._supportedCharsetNames.push(codingSM.getCodingStateMachine());
|
|
50
|
+
}
|
|
51
|
+
self.reset();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.reset = function() {
|
|
55
|
+
EscCharSetProber.prototype.reset.apply(this);
|
|
56
|
+
for( var i = 0, codingSM; codingSM = this._mCodingSM[i]; i++ ) {
|
|
57
|
+
if( !codingSM ) continue;
|
|
58
|
+
codingSM.active = true;
|
|
59
|
+
codingSM.reset();
|
|
60
|
+
}
|
|
61
|
+
this._mActiveSM = self._mCodingSM.length;
|
|
62
|
+
this._mDetectedCharset = null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.getCharsetName = function() {
|
|
66
|
+
return this._mDetectedCharset;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.getSupportedCharsetNames = function() {
|
|
70
|
+
return self._supportedCharsetNames;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.getConfidence = function() {
|
|
74
|
+
if( this._mDetectedCharset ) {
|
|
75
|
+
return 0.99;
|
|
76
|
+
} else {
|
|
77
|
+
return 0.00;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.feed = function(aBuf) {
|
|
82
|
+
for( var i = 0, c; i < aBuf.length; i++ ) {
|
|
83
|
+
c = aBuf[i];
|
|
84
|
+
for( var j = 0, codingSM; codingSM = this._mCodingSM[j]; j++ ) {
|
|
85
|
+
if( !codingSM || !codingSM.active ) continue;
|
|
86
|
+
var codingState = codingSM.nextState(c);
|
|
87
|
+
if( codingState == constants.error ) {
|
|
88
|
+
codingSM.active = false;
|
|
89
|
+
this._mActiveSM--;
|
|
90
|
+
if( this._mActiveSM <= 0 ) {
|
|
91
|
+
this._mState = constants.notMe;
|
|
92
|
+
return this.getState();
|
|
93
|
+
}
|
|
94
|
+
} else if( codingState == constants.itsMe ) {
|
|
95
|
+
this._mState = constants.foundIt;
|
|
96
|
+
this._mDetectedCharset = codingSM.getCodingStateMachine();
|
|
97
|
+
return this.getState();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return this.getState();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
init();
|
|
106
|
+
}
|
|
107
|
+
EscCharSetProber.prototype = new CharSetProber();
|
|
108
|
+
|
|
109
|
+
module.exports = EscCharSetProber
|
package/src/escsm.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The Original Code is Mozilla Universal charset detector code.
|
|
3
|
+
*
|
|
4
|
+
* The Initial Developer of the Original Code is
|
|
5
|
+
* Netscape Communications Corporation.
|
|
6
|
+
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
7
|
+
* the Initial Developer. All Rights Reserved.
|
|
8
|
+
*
|
|
9
|
+
* Contributor(s):
|
|
10
|
+
* António Afonso (antonio.afonso gmail.com) - port to JavaScript
|
|
11
|
+
* Mark Pilgrim - port to Python
|
|
12
|
+
* Shy Shalom - original C code
|
|
13
|
+
*
|
|
14
|
+
* This library is free software; you can redistribute it and/or
|
|
15
|
+
* modify it under the terms of the GNU Lesser General Public
|
|
16
|
+
* License as published by the Free Software Foundation; either
|
|
17
|
+
* version 2.1 of the License, or (at your option) any later version.
|
|
18
|
+
*
|
|
19
|
+
* This library is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
22
|
+
* Lesser General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
25
|
+
* License along with this library; if not, write to the Free Software
|
|
26
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
27
|
+
* 02110-1301 USA
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
var consts = require('./constants');
|
|
31
|
+
|
|
32
|
+
var HZ_cls = [
|
|
33
|
+
1,0,0,0,0,0,0,0, // 00 - 07
|
|
34
|
+
0,0,0,0,0,0,0,0, // 08 - 0f
|
|
35
|
+
0,0,0,0,0,0,0,0, // 10 - 17
|
|
36
|
+
0,0,0,1,0,0,0,0, // 18 - 1f
|
|
37
|
+
0,0,0,0,0,0,0,0, // 20 - 27
|
|
38
|
+
0,0,0,0,0,0,0,0, // 28 - 2f
|
|
39
|
+
0,0,0,0,0,0,0,0, // 30 - 37
|
|
40
|
+
0,0,0,0,0,0,0,0, // 38 - 3f
|
|
41
|
+
0,0,0,0,0,0,0,0, // 40 - 47
|
|
42
|
+
0,0,0,0,0,0,0,0, // 48 - 4f
|
|
43
|
+
0,0,0,0,0,0,0,0, // 50 - 57
|
|
44
|
+
0,0,0,0,0,0,0,0, // 58 - 5f
|
|
45
|
+
0,0,0,0,0,0,0,0, // 60 - 67
|
|
46
|
+
0,0,0,0,0,0,0,0, // 68 - 6f
|
|
47
|
+
0,0,0,0,0,0,0,0, // 70 - 77
|
|
48
|
+
0,0,0,4,0,5,2,0, // 78 - 7f
|
|
49
|
+
1,1,1,1,1,1,1,1, // 80 - 87
|
|
50
|
+
1,1,1,1,1,1,1,1, // 88 - 8f
|
|
51
|
+
1,1,1,1,1,1,1,1, // 90 - 97
|
|
52
|
+
1,1,1,1,1,1,1,1, // 98 - 9f
|
|
53
|
+
1,1,1,1,1,1,1,1, // a0 - a7
|
|
54
|
+
1,1,1,1,1,1,1,1, // a8 - af
|
|
55
|
+
1,1,1,1,1,1,1,1, // b0 - b7
|
|
56
|
+
1,1,1,1,1,1,1,1, // b8 - bf
|
|
57
|
+
1,1,1,1,1,1,1,1, // c0 - c7
|
|
58
|
+
1,1,1,1,1,1,1,1, // c8 - cf
|
|
59
|
+
1,1,1,1,1,1,1,1, // d0 - d7
|
|
60
|
+
1,1,1,1,1,1,1,1, // d8 - df
|
|
61
|
+
1,1,1,1,1,1,1,1, // e0 - e7
|
|
62
|
+
1,1,1,1,1,1,1,1, // e8 - ef
|
|
63
|
+
1,1,1,1,1,1,1,1, // f0 - f7
|
|
64
|
+
1,1,1,1,1,1,1,1 // f8 - ff
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
var HZ_st = [
|
|
68
|
+
consts.start,consts.error, 3,consts.start,consts.start,consts.start,consts.error,consts.error, // 00-07
|
|
69
|
+
consts.error,consts.error,consts.error,consts.error,consts.itsMe,consts.itsMe,consts.itsMe,consts.itsMe, // 08-0f
|
|
70
|
+
consts.itsMe,consts.itsMe,consts.error,consts.error,consts.start,consts.start, 4,consts.error, // 10-17
|
|
71
|
+
5,consts.error, 6,consts.error, 5, 5, 4,consts.error, // 18-1f
|
|
72
|
+
4,consts.error, 4, 4, 4,consts.error, 4,consts.error, // 20-27
|
|
73
|
+
4,consts.itsMe,consts.start,consts.start,consts.start,consts.start,consts.start,consts.start // 28-2f
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
var HZCharLenTable = [0, 0, 0, 0, 0, 0];
|
|
77
|
+
|
|
78
|
+
exports.HZSMModel = {
|
|
79
|
+
"classTable" : HZ_cls,
|
|
80
|
+
"classFactor" : 6,
|
|
81
|
+
"stateTable" : HZ_st,
|
|
82
|
+
"charLenTable" : HZCharLenTable,
|
|
83
|
+
"name" : "HZ-GB-2312"
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
var ISO2022CN_cls = [
|
|
87
|
+
2,0,0,0,0,0,0,0, // 00 - 07
|
|
88
|
+
0,0,0,0,0,0,0,0, // 08 - 0f
|
|
89
|
+
0,0,0,0,0,0,0,0, // 10 - 17
|
|
90
|
+
0,0,0,1,0,0,0,0, // 18 - 1f
|
|
91
|
+
0,0,0,0,0,0,0,0, // 20 - 27
|
|
92
|
+
0,3,0,0,0,0,0,0, // 28 - 2f
|
|
93
|
+
0,0,0,0,0,0,0,0, // 30 - 37
|
|
94
|
+
0,0,0,0,0,0,0,0, // 38 - 3f
|
|
95
|
+
0,0,0,4,0,0,0,0, // 40 - 47
|
|
96
|
+
0,0,0,0,0,0,0,0, // 48 - 4f
|
|
97
|
+
0,0,0,0,0,0,0,0, // 50 - 57
|
|
98
|
+
0,0,0,0,0,0,0,0, // 58 - 5f
|
|
99
|
+
0,0,0,0,0,0,0,0, // 60 - 67
|
|
100
|
+
0,0,0,0,0,0,0,0, // 68 - 6f
|
|
101
|
+
0,0,0,0,0,0,0,0, // 70 - 77
|
|
102
|
+
0,0,0,0,0,0,0,0, // 78 - 7f
|
|
103
|
+
2,2,2,2,2,2,2,2, // 80 - 87
|
|
104
|
+
2,2,2,2,2,2,2,2, // 88 - 8f
|
|
105
|
+
2,2,2,2,2,2,2,2, // 90 - 97
|
|
106
|
+
2,2,2,2,2,2,2,2, // 98 - 9f
|
|
107
|
+
2,2,2,2,2,2,2,2, // a0 - a7
|
|
108
|
+
2,2,2,2,2,2,2,2, // a8 - af
|
|
109
|
+
2,2,2,2,2,2,2,2, // b0 - b7
|
|
110
|
+
2,2,2,2,2,2,2,2, // b8 - bf
|
|
111
|
+
2,2,2,2,2,2,2,2, // c0 - c7
|
|
112
|
+
2,2,2,2,2,2,2,2, // c8 - cf
|
|
113
|
+
2,2,2,2,2,2,2,2, // d0 - d7
|
|
114
|
+
2,2,2,2,2,2,2,2, // d8 - df
|
|
115
|
+
2,2,2,2,2,2,2,2, // e0 - e7
|
|
116
|
+
2,2,2,2,2,2,2,2, // e8 - ef
|
|
117
|
+
2,2,2,2,2,2,2,2, // f0 - f7
|
|
118
|
+
2,2,2,2,2,2,2,2 // f8 - ff
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
var ISO2022CN_st = [
|
|
122
|
+
consts.start, 3,consts.error,consts.start,consts.start,consts.start,consts.start,consts.start, // 00-07
|
|
123
|
+
consts.start,consts.error,consts.error,consts.error,consts.error,consts.error,consts.error,consts.error, // 08-0f
|
|
124
|
+
consts.error,consts.error,consts.itsMe,consts.itsMe,consts.itsMe,consts.itsMe,consts.itsMe,consts.itsMe, // 10-17
|
|
125
|
+
consts.itsMe,consts.itsMe,consts.itsMe,consts.error,consts.error,consts.error, 4,consts.error, // 18-1f
|
|
126
|
+
consts.error,consts.error,consts.error,consts.itsMe,consts.error,consts.error,consts.error,consts.error, // 20-27
|
|
127
|
+
5, 6,consts.error,consts.error,consts.error,consts.error,consts.error,consts.error, // 28-2f
|
|
128
|
+
consts.error,consts.error,consts.error,consts.itsMe,consts.error,consts.error,consts.error,consts.error, // 30-37
|
|
129
|
+
consts.error,consts.error,consts.error,consts.error,consts.error,consts.itsMe,consts.error,consts.start // 38-3f
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
var ISO2022CNCharLenTable = [0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
133
|
+
|
|
134
|
+
exports.ISO2022CNSMModel = {
|
|
135
|
+
"classTable" : ISO2022CN_cls,
|
|
136
|
+
"classFactor" : 9,
|
|
137
|
+
"stateTable" : ISO2022CN_st,
|
|
138
|
+
"charLenTable" : ISO2022CNCharLenTable,
|
|
139
|
+
"name" : "ISO-2022-CN"
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
var ISO2022JP_cls = [
|
|
143
|
+
2,0,0,0,0,0,0,0, // 00 - 07
|
|
144
|
+
0,0,0,0,0,0,2,2, // 08 - 0f
|
|
145
|
+
0,0,0,0,0,0,0,0, // 10 - 17
|
|
146
|
+
0,0,0,1,0,0,0,0, // 18 - 1f
|
|
147
|
+
0,0,0,0,7,0,0,0, // 20 - 27
|
|
148
|
+
3,0,0,0,0,0,0,0, // 28 - 2f
|
|
149
|
+
0,0,0,0,0,0,0,0, // 30 - 37
|
|
150
|
+
0,0,0,0,0,0,0,0, // 38 - 3f
|
|
151
|
+
6,0,4,0,8,0,0,0, // 40 - 47
|
|
152
|
+
0,9,5,0,0,0,0,0, // 48 - 4f
|
|
153
|
+
0,0,0,0,0,0,0,0, // 50 - 57
|
|
154
|
+
0,0,0,0,0,0,0,0, // 58 - 5f
|
|
155
|
+
0,0,0,0,0,0,0,0, // 60 - 67
|
|
156
|
+
0,0,0,0,0,0,0,0, // 68 - 6f
|
|
157
|
+
0,0,0,0,0,0,0,0, // 70 - 77
|
|
158
|
+
0,0,0,0,0,0,0,0, // 78 - 7f
|
|
159
|
+
2,2,2,2,2,2,2,2, // 80 - 87
|
|
160
|
+
2,2,2,2,2,2,2,2, // 88 - 8f
|
|
161
|
+
2,2,2,2,2,2,2,2, // 90 - 97
|
|
162
|
+
2,2,2,2,2,2,2,2, // 98 - 9f
|
|
163
|
+
2,2,2,2,2,2,2,2, // a0 - a7
|
|
164
|
+
2,2,2,2,2,2,2,2, // a8 - af
|
|
165
|
+
2,2,2,2,2,2,2,2, // b0 - b7
|
|
166
|
+
2,2,2,2,2,2,2,2, // b8 - bf
|
|
167
|
+
2,2,2,2,2,2,2,2, // c0 - c7
|
|
168
|
+
2,2,2,2,2,2,2,2, // c8 - cf
|
|
169
|
+
2,2,2,2,2,2,2,2, // d0 - d7
|
|
170
|
+
2,2,2,2,2,2,2,2, // d8 - df
|
|
171
|
+
2,2,2,2,2,2,2,2, // e0 - e7
|
|
172
|
+
2,2,2,2,2,2,2,2, // e8 - ef
|
|
173
|
+
2,2,2,2,2,2,2,2, // f0 - f7
|
|
174
|
+
2,2,2,2,2,2,2,2 // f8 - ff
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
var ISO2022JP_st = [
|
|
178
|
+
consts.start, 3,consts.error,consts.start,consts.start,consts.start,consts.start,consts.start, // 00-07
|
|
179
|
+
consts.start,consts.start,consts.error,consts.error,consts.error,consts.error,consts.error,consts.error, // 08-0f
|
|
180
|
+
consts.error,consts.error,consts.error,consts.error,consts.itsMe,consts.itsMe,consts.itsMe,consts.itsMe, // 10-17
|
|
181
|
+
consts.itsMe,consts.itsMe,consts.itsMe,consts.itsMe,consts.itsMe,consts.itsMe,consts.error,consts.error, // 18-1f
|
|
182
|
+
consts.error, 5,consts.error,consts.error,consts.error, 4,consts.error,consts.error, // 20-27
|
|
183
|
+
consts.error,consts.error,consts.error, 6,consts.itsMe,consts.error,consts.itsMe,consts.error, // 28-2f
|
|
184
|
+
consts.error,consts.error,consts.error,consts.error,consts.error,consts.error,consts.itsMe,consts.itsMe, // 30-37
|
|
185
|
+
consts.error,consts.error,consts.error,consts.itsMe,consts.error,consts.error,consts.error,consts.error, // 38-3f
|
|
186
|
+
consts.error,consts.error,consts.error,consts.error,consts.itsMe,consts.error,consts.start,consts.start // 40-47
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
var ISO2022JPCharLenTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
190
|
+
|
|
191
|
+
exports.ISO2022JPSMModel = {
|
|
192
|
+
"classTable" : ISO2022JP_cls,
|
|
193
|
+
"classFactor" : 10,
|
|
194
|
+
"stateTable" : ISO2022JP_st,
|
|
195
|
+
"charLenTable" : ISO2022JPCharLenTable,
|
|
196
|
+
"name" : "ISO-2022-JP"
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
var ISO2022KR_cls = [
|
|
200
|
+
2,0,0,0,0,0,0,0, // 00 - 07
|
|
201
|
+
0,0,0,0,0,0,0,0, // 08 - 0f
|
|
202
|
+
0,0,0,0,0,0,0,0, // 10 - 17
|
|
203
|
+
0,0,0,1,0,0,0,0, // 18 - 1f
|
|
204
|
+
0,0,0,0,3,0,0,0, // 20 - 27
|
|
205
|
+
0,4,0,0,0,0,0,0, // 28 - 2f
|
|
206
|
+
0,0,0,0,0,0,0,0, // 30 - 37
|
|
207
|
+
0,0,0,0,0,0,0,0, // 38 - 3f
|
|
208
|
+
0,0,0,5,0,0,0,0, // 40 - 47
|
|
209
|
+
0,0,0,0,0,0,0,0, // 48 - 4f
|
|
210
|
+
0,0,0,0,0,0,0,0, // 50 - 57
|
|
211
|
+
0,0,0,0,0,0,0,0, // 58 - 5f
|
|
212
|
+
0,0,0,0,0,0,0,0, // 60 - 67
|
|
213
|
+
0,0,0,0,0,0,0,0, // 68 - 6f
|
|
214
|
+
0,0,0,0,0,0,0,0, // 70 - 77
|
|
215
|
+
0,0,0,0,0,0,0,0, // 78 - 7f
|
|
216
|
+
2,2,2,2,2,2,2,2, // 80 - 87
|
|
217
|
+
2,2,2,2,2,2,2,2, // 88 - 8f
|
|
218
|
+
2,2,2,2,2,2,2,2, // 90 - 97
|
|
219
|
+
2,2,2,2,2,2,2,2, // 98 - 9f
|
|
220
|
+
2,2,2,2,2,2,2,2, // a0 - a7
|
|
221
|
+
2,2,2,2,2,2,2,2, // a8 - af
|
|
222
|
+
2,2,2,2,2,2,2,2, // b0 - b7
|
|
223
|
+
2,2,2,2,2,2,2,2, // b8 - bf
|
|
224
|
+
2,2,2,2,2,2,2,2, // c0 - c7
|
|
225
|
+
2,2,2,2,2,2,2,2, // c8 - cf
|
|
226
|
+
2,2,2,2,2,2,2,2, // d0 - d7
|
|
227
|
+
2,2,2,2,2,2,2,2, // d8 - df
|
|
228
|
+
2,2,2,2,2,2,2,2, // e0 - e7
|
|
229
|
+
2,2,2,2,2,2,2,2, // e8 - ef
|
|
230
|
+
2,2,2,2,2,2,2,2, // f0 - f7
|
|
231
|
+
2,2,2,2,2,2,2,2 // f8 - ff
|
|
232
|
+
];
|
|
233
|
+
|
|
234
|
+
var ISO2022KR_st = [
|
|
235
|
+
consts.start, 3,consts.error,consts.start,consts.start,consts.start,consts.error,consts.error, // 00-07
|
|
236
|
+
consts.error,consts.error,consts.error,consts.error,consts.itsMe,consts.itsMe,consts.itsMe,consts.itsMe, // 08-0f
|
|
237
|
+
consts.itsMe,consts.itsMe,consts.error,consts.error,consts.error, 4,consts.error,consts.error, // 10-17
|
|
238
|
+
consts.error,consts.error,consts.error,consts.error, 5,consts.error,consts.error,consts.error, // 18-1f
|
|
239
|
+
consts.error,consts.error,consts.error,consts.itsMe,consts.start,consts.start,consts.start,consts.start // 20-27
|
|
240
|
+
];
|
|
241
|
+
|
|
242
|
+
var ISO2022KRCharLenTable = [0, 0, 0, 0, 0, 0];
|
|
243
|
+
|
|
244
|
+
exports.ISO2022KRSMModel = {
|
|
245
|
+
"classTable" : ISO2022KR_cls,
|
|
246
|
+
"classFactor" : 6,
|
|
247
|
+
"stateTable" : ISO2022KR_st,
|
|
248
|
+
"charLenTable" : ISO2022KRCharLenTable,
|
|
249
|
+
"name" : "ISO-2022-KR"
|
|
250
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The Original Code is Mozilla Universal charset detector code.
|
|
3
|
+
*
|
|
4
|
+
* The Initial Developer of the Original Code is
|
|
5
|
+
* Netscape Communications Corporation.
|
|
6
|
+
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
7
|
+
* the Initial Developer. All Rights Reserved.
|
|
8
|
+
*
|
|
9
|
+
* Contributor(s):
|
|
10
|
+
* António Afonso (antonio.afonso gmail.com) - port to JavaScript
|
|
11
|
+
* Mark Pilgrim - port to Python
|
|
12
|
+
* Shy Shalom - original C code
|
|
13
|
+
*
|
|
14
|
+
* This library is free software; you can redistribute it and/or
|
|
15
|
+
* modify it under the terms of the GNU Lesser General Public
|
|
16
|
+
* License as published by the Free Software Foundation; either
|
|
17
|
+
* version 2.1 of the License, or (at your option) any later version.
|
|
18
|
+
*
|
|
19
|
+
* This library is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
22
|
+
* Lesser General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
25
|
+
* License along with this library; if not, write to the Free Software
|
|
26
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
27
|
+
* 02110-1301 USA
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
var CodingStateMachine = require('./codingstatemachine');
|
|
31
|
+
var MultiByteCharSetProber = require('./mbcharsetprober');
|
|
32
|
+
var EUCJPDistributionAnalysis = require('./chardistribution').EUCJPDistributionAnalysis;
|
|
33
|
+
var EUCJPContextAnalysis = require('./jpcntx').EUCJPContextAnalysis;
|
|
34
|
+
var EUCJPSMModel = require('./mbcssm/eucjp');
|
|
35
|
+
var constants = require('./constants');
|
|
36
|
+
var logger = require('./logger');
|
|
37
|
+
|
|
38
|
+
function EUCJPProber() {
|
|
39
|
+
MultiByteCharSetProber.apply(this);
|
|
40
|
+
|
|
41
|
+
var self = this;
|
|
42
|
+
|
|
43
|
+
function init() {
|
|
44
|
+
self._mCodingSM = new CodingStateMachine(EUCJPSMModel);
|
|
45
|
+
self._mDistributionAnalyzer = new EUCJPDistributionAnalysis();
|
|
46
|
+
self._mContextAnalyzer = new EUCJPContextAnalysis();
|
|
47
|
+
self.reset();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.reset = function() {
|
|
51
|
+
EUCJPProber.prototype.reset.apply(this);
|
|
52
|
+
this._mContextAnalyzer.reset();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.getCharsetName = function() {
|
|
56
|
+
return "EUC-JP";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.feed = function(aBuf) {
|
|
60
|
+
var aLen = aBuf.length;
|
|
61
|
+
for( var i = 0; i < aLen; i++ ) {
|
|
62
|
+
var codingState = this._mCodingSM.nextState(aBuf[i]);
|
|
63
|
+
if( codingState == constants.error ) {
|
|
64
|
+
logger.log(this.getCharsetName() + " prober hit error at byte " + i + "\n");
|
|
65
|
+
this._mState = constants.notMe;
|
|
66
|
+
break;
|
|
67
|
+
} else if( codingState == constants.itsMe ) {
|
|
68
|
+
this._mState = constants.foundIt;
|
|
69
|
+
break;
|
|
70
|
+
} else if( codingState == constants.start ) {
|
|
71
|
+
var charLen = this._mCodingSM.getCurrentCharLen();
|
|
72
|
+
if( i == 0 ) {
|
|
73
|
+
this._mLastChar[1] = aBuf[0];
|
|
74
|
+
var lastCharStr = this._mLastChar.join('');
|
|
75
|
+
this._mContextAnalyzer.feed(lastCharStr, charLen);
|
|
76
|
+
this._mDistributionAnalyzer.feed(lastCharStr, charLen);
|
|
77
|
+
} else {
|
|
78
|
+
this._mContextAnalyzer.feed(aBuf.slice(i-1,i+1), charLen);
|
|
79
|
+
this._mDistributionAnalyzer.feed(aBuf.slice(i-1,i+1), charLen);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this._mLastChar[0] = aBuf[aLen - 1];
|
|
85
|
+
|
|
86
|
+
if( this.getState() == constants.detecting ) {
|
|
87
|
+
if( this._mContextAnalyzer.gotEnoughData() &&
|
|
88
|
+
this.getConfidence() > constants.SHORTCUT_THRESHOLD ) {
|
|
89
|
+
this._mState = constants.foundIt;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return this.getState();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
this.getConfidence = function() {
|
|
97
|
+
var contxtCf = this._mContextAnalyzer.getConfidence();
|
|
98
|
+
var distribCf = this._mDistributionAnalyzer.getConfidence();
|
|
99
|
+
|
|
100
|
+
return Math.max(contxtCf, distribCf);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
init();
|
|
104
|
+
}
|
|
105
|
+
EUCJPProber.prototype = new MultiByteCharSetProber();
|
|
106
|
+
|
|
107
|
+
module.exports = EUCJPProber
|