@loaders.gl/polyfills 3.2.12 → 3.3.0-alpha.10
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/dist/dist.min.js +120 -33
- package/dist/es5/bundle.js +0 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +12 -33
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/encoding-indexes.js.map +1 -1
- package/dist/es5/lib/encoding.js +255 -135
- package/dist/es5/lib/encoding.js.map +1 -1
- package/dist/es5/node/buffer/btoa.node.js +0 -1
- package/dist/es5/node/buffer/btoa.node.js.map +1 -1
- package/dist/es5/node/buffer/to-array-buffer.node.js +0 -2
- package/dist/es5/node/buffer/to-array-buffer.node.js.map +1 -1
- package/dist/es5/node/fetch/fetch.node.js +2 -36
- package/dist/es5/node/fetch/fetch.node.js.map +1 -1
- package/dist/es5/node/fetch/headers.node.js +0 -21
- package/dist/es5/node/fetch/headers.node.js.map +1 -1
- package/dist/es5/node/fetch/response.node.js +10 -45
- package/dist/es5/node/fetch/response.node.js.map +1 -1
- package/dist/es5/node/fetch/utils/decode-data-uri.node.js +0 -8
- package/dist/es5/node/fetch/utils/decode-data-uri.node.js.map +1 -1
- package/dist/es5/node/fetch/utils/stream-utils.node.js +10 -40
- package/dist/es5/node/fetch/utils/stream-utils.node.js.map +1 -1
- package/dist/es5/node/file/blob-stream-controller.js +5 -19
- package/dist/es5/node/file/blob-stream-controller.js.map +1 -1
- package/dist/es5/node/file/blob-stream.js +5 -30
- package/dist/es5/node/file/blob-stream.js.map +1 -1
- package/dist/es5/node/file/blob.js +17 -50
- package/dist/es5/node/file/blob.js.map +1 -1
- package/dist/es5/node/file/file-reader.js +1 -28
- package/dist/es5/node/file/file-reader.js.map +1 -1
- package/dist/es5/node/file/file.js +0 -18
- package/dist/es5/node/file/file.js.map +1 -1
- package/dist/es5/node/file/install-file-polyfills.js +0 -7
- package/dist/es5/node/file/install-file-polyfills.js.map +1 -1
- package/dist/es5/node/file/readable-stream.js +2 -14
- package/dist/es5/node/file/readable-stream.js.map +1 -1
- package/dist/es5/node/images/encode-image.node.js +2 -6
- package/dist/es5/node/images/encode-image.node.js.map +1 -1
- package/dist/es5/node/images/parse-image.node.js +5 -14
- package/dist/es5/node/images/parse-image.node.js.map +1 -1
- package/dist/es5/promise/all-settled.js +2 -2
- package/dist/es5/promise/all-settled.js.map +1 -1
- package/dist/es5/utils/assert.js +0 -1
- package/dist/es5/utils/assert.js.map +1 -1
- package/dist/es5/utils/globals.js +3 -4
- package/dist/es5/utils/globals.js.map +1 -1
- package/dist/esm/bundle.js +1 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/index.js +4 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/encoding-indexes.js +2 -0
- package/dist/esm/lib/encoding-indexes.js.map +1 -1
- package/dist/esm/lib/encoding.js +256 -131
- package/dist/esm/lib/encoding.js.map +1 -1
- package/dist/esm/node/buffer/btoa.node.js +2 -0
- package/dist/esm/node/buffer/btoa.node.js.map +1 -1
- package/dist/esm/node/buffer/to-array-buffer.node.js +0 -1
- package/dist/esm/node/buffer/to-array-buffer.node.js.map +1 -1
- package/dist/esm/node/fetch/fetch.node.js +5 -17
- package/dist/esm/node/fetch/fetch.node.js.map +1 -1
- package/dist/esm/node/fetch/headers.node.js +2 -24
- package/dist/esm/node/fetch/headers.node.js.map +1 -1
- package/dist/esm/node/fetch/response.node.js +0 -17
- package/dist/esm/node/fetch/response.node.js.map +1 -1
- package/dist/esm/node/fetch/utils/decode-data-uri.node.js +3 -6
- package/dist/esm/node/fetch/utils/decode-data-uri.node.js.map +1 -1
- package/dist/esm/node/fetch/utils/stream-utils.node.js +4 -7
- package/dist/esm/node/fetch/utils/stream-utils.node.js.map +1 -1
- package/dist/esm/node/file/blob-stream-controller.js +0 -8
- package/dist/esm/node/file/blob-stream-controller.js.map +1 -1
- package/dist/esm/node/file/blob-stream.js +1 -5
- package/dist/esm/node/file/blob-stream.js.map +1 -1
- package/dist/esm/node/file/blob.js +12 -21
- package/dist/esm/node/file/blob.js.map +1 -1
- package/dist/esm/node/file/file-reader.js +1 -24
- package/dist/esm/node/file/file-reader.js.map +1 -1
- package/dist/esm/node/file/file.js +4 -9
- package/dist/esm/node/file/file.js.map +1 -1
- package/dist/esm/node/file/install-file-polyfills.js +0 -2
- package/dist/esm/node/file/install-file-polyfills.js.map +1 -1
- package/dist/esm/node/file/readable-stream.js +2 -0
- package/dist/esm/node/file/readable-stream.js.map +1 -1
- package/dist/esm/node/images/encode-image.node.js +4 -0
- package/dist/esm/node/images/encode-image.node.js.map +1 -1
- package/dist/esm/node/images/parse-image.node.js +5 -1
- package/dist/esm/node/images/parse-image.node.js.map +1 -1
- package/dist/esm/promise/all-settled.js +1 -0
- package/dist/esm/promise/all-settled.js.map +1 -1
- package/dist/esm/utils/assert.js.map +1 -1
- package/dist/esm/utils/globals.js +4 -1
- package/dist/esm/utils/globals.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/libs/encoding-indexes-asian.d.ts +1 -1
- package/dist/node/images/parse-image.node.d.ts +1 -1
- package/dist/node/images/parse-image.node.d.ts.map +1 -1
- package/dist/node/images/parse-image.node.js +2 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/node/images/parse-image.node.ts +2 -1
package/dist/es5/lib/encoding.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.TextEncoder = TextEncoder;
|
|
9
7
|
exports.TextDecoder = TextDecoder;
|
|
10
|
-
|
|
8
|
+
exports.TextEncoder = TextEncoder;
|
|
11
9
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
12
|
-
|
|
13
10
|
var _encodingIndexes = _interopRequireDefault(require("./encoding-indexes"));
|
|
14
11
|
|
|
15
12
|
global['encoding-indexes'] = _encodingIndexes.default || {};
|
|
@@ -21,7 +18,6 @@ function inRange(a, min, max) {
|
|
|
21
18
|
function includes(array, item) {
|
|
22
19
|
return array.indexOf(item) !== -1;
|
|
23
20
|
}
|
|
24
|
-
|
|
25
21
|
var floor = Math.floor;
|
|
26
22
|
|
|
27
23
|
function ToDictionary(o) {
|
|
@@ -31,9 +27,13 @@ function ToDictionary(o) {
|
|
|
31
27
|
}
|
|
32
28
|
|
|
33
29
|
function stringToCodePoints(string) {
|
|
30
|
+
|
|
34
31
|
var s = String(string);
|
|
32
|
+
|
|
35
33
|
var n = s.length;
|
|
34
|
+
|
|
36
35
|
var i = 0;
|
|
36
|
+
|
|
37
37
|
var u = [];
|
|
38
38
|
|
|
39
39
|
while (i < n) {
|
|
@@ -41,25 +41,35 @@ function stringToCodePoints(string) {
|
|
|
41
41
|
|
|
42
42
|
if (c < 0xd800 || c > 0xdfff) {
|
|
43
43
|
u.push(c);
|
|
44
|
-
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
else if (0xdc00 <= c && c <= 0xdfff) {
|
|
47
|
+
u.push(0xfffd);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
else if (0xd800 <= c && c <= 0xdbff) {
|
|
51
|
+
if (i === n - 1) {
|
|
45
52
|
u.push(0xfffd);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
u.push(0xfffd);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
var d = s.charCodeAt(i + 1);
|
|
56
|
+
|
|
57
|
+
if (0xdc00 <= d && d <= 0xdfff) {
|
|
58
|
+
var a = c & 0x3ff;
|
|
59
|
+
|
|
60
|
+
var b = d & 0x3ff;
|
|
61
|
+
|
|
62
|
+
u.push(0x10000 + (a << 10) + b);
|
|
63
|
+
|
|
64
|
+
i += 1;
|
|
61
65
|
}
|
|
62
66
|
|
|
67
|
+
else {
|
|
68
|
+
u.push(0xfffd);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
63
73
|
i += 1;
|
|
64
74
|
}
|
|
65
75
|
|
|
@@ -68,10 +78,8 @@ function stringToCodePoints(string) {
|
|
|
68
78
|
|
|
69
79
|
function codePointsToString(code_points) {
|
|
70
80
|
var s = '';
|
|
71
|
-
|
|
72
81
|
for (var i = 0; i < code_points.length; ++i) {
|
|
73
82
|
var cp = code_points[i];
|
|
74
|
-
|
|
75
83
|
if (cp <= 0xffff) {
|
|
76
84
|
s += String.fromCharCode(cp);
|
|
77
85
|
} else {
|
|
@@ -79,7 +87,6 @@ function codePointsToString(code_points) {
|
|
|
79
87
|
s += String.fromCharCode((cp >> 10) + 0xd800, (cp & 0x3ff) + 0xdc00);
|
|
80
88
|
}
|
|
81
89
|
}
|
|
82
|
-
|
|
83
90
|
return s;
|
|
84
91
|
}
|
|
85
92
|
|
|
@@ -88,13 +95,13 @@ function isASCIIByte(a) {
|
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
var isASCIICodePoint = isASCIIByte;
|
|
98
|
+
|
|
91
99
|
var end_of_stream = -1;
|
|
92
100
|
|
|
93
101
|
function Stream(tokens) {
|
|
94
102
|
this.tokens = [].slice.call(tokens);
|
|
95
103
|
this.tokens.reverse();
|
|
96
104
|
}
|
|
97
|
-
|
|
98
105
|
Stream.prototype = {
|
|
99
106
|
endOfStream: function endOfStream() {
|
|
100
107
|
return !this.tokens.length;
|
|
@@ -106,7 +113,6 @@ Stream.prototype = {
|
|
|
106
113
|
prepend: function prepend(token) {
|
|
107
114
|
if (Array.isArray(token)) {
|
|
108
115
|
var tokens = token;
|
|
109
|
-
|
|
110
116
|
while (tokens.length) {
|
|
111
117
|
this.tokens.push(tokens.pop());
|
|
112
118
|
}
|
|
@@ -117,7 +123,6 @@ Stream.prototype = {
|
|
|
117
123
|
push: function push(token) {
|
|
118
124
|
if (Array.isArray(token)) {
|
|
119
125
|
var tokens = token;
|
|
120
|
-
|
|
121
126
|
while (tokens.length) {
|
|
122
127
|
this.tokens.unshift(tokens.shift());
|
|
123
128
|
}
|
|
@@ -126,6 +131,7 @@ Stream.prototype = {
|
|
|
126
131
|
}
|
|
127
132
|
}
|
|
128
133
|
};
|
|
134
|
+
|
|
129
135
|
var finished = -1;
|
|
130
136
|
|
|
131
137
|
function decoderError(fatal, opt_code_point) {
|
|
@@ -138,13 +144,11 @@ function encoderError(code_point) {
|
|
|
138
144
|
}
|
|
139
145
|
|
|
140
146
|
function Decoder() {}
|
|
141
|
-
|
|
142
147
|
Decoder.prototype = {
|
|
143
148
|
handler: function handler(stream, bite) {}
|
|
144
149
|
};
|
|
145
150
|
|
|
146
151
|
function Encoder() {}
|
|
147
|
-
|
|
148
152
|
Encoder.prototype = {
|
|
149
153
|
handler: function handler(stream, code_point) {}
|
|
150
154
|
};
|
|
@@ -155,7 +159,6 @@ function getEncoding(label) {
|
|
|
155
159
|
if (Object.prototype.hasOwnProperty.call(label_to_encoding, label)) {
|
|
156
160
|
return label_to_encoding[label];
|
|
157
161
|
}
|
|
158
|
-
|
|
159
162
|
return null;
|
|
160
163
|
}
|
|
161
164
|
|
|
@@ -301,6 +304,7 @@ var encodings = [{
|
|
|
301
304
|
}],
|
|
302
305
|
heading: 'Legacy miscellaneous encodings'
|
|
303
306
|
}];
|
|
307
|
+
|
|
304
308
|
var label_to_encoding = {};
|
|
305
309
|
encodings.forEach(function (category) {
|
|
306
310
|
category.encodings.forEach(function (encoding) {
|
|
@@ -309,6 +313,7 @@ encodings.forEach(function (category) {
|
|
|
309
313
|
});
|
|
310
314
|
});
|
|
311
315
|
});
|
|
316
|
+
|
|
312
317
|
var encoders = {};
|
|
313
318
|
var decoders = {};
|
|
314
319
|
|
|
@@ -326,21 +331,20 @@ function index(name) {
|
|
|
326
331
|
if (!('encoding-indexes' in global)) {
|
|
327
332
|
throw Error('Indexes missing.' + ' Did you forget to include encoding-indexes.js first?');
|
|
328
333
|
}
|
|
329
|
-
|
|
330
334
|
return global['encoding-indexes'][name];
|
|
331
335
|
}
|
|
332
336
|
|
|
333
337
|
function indexGB18030RangesCodePointFor(pointer) {
|
|
334
338
|
if (pointer > 39419 && pointer < 189000 || pointer > 1237575) return null;
|
|
339
|
+
|
|
335
340
|
if (pointer === 7457) return 0xe7c7;
|
|
341
|
+
|
|
336
342
|
var offset = 0;
|
|
337
343
|
var code_point_offset = 0;
|
|
338
344
|
var idx = index('gb18030-ranges');
|
|
339
345
|
var i;
|
|
340
|
-
|
|
341
346
|
for (i = 0; i < idx.length; ++i) {
|
|
342
347
|
var entry = idx[i];
|
|
343
|
-
|
|
344
348
|
if (entry[0] <= pointer) {
|
|
345
349
|
offset = entry[0];
|
|
346
350
|
code_point_offset = entry[1];
|
|
@@ -354,14 +358,13 @@ function indexGB18030RangesCodePointFor(pointer) {
|
|
|
354
358
|
|
|
355
359
|
function indexGB18030RangesPointerFor(code_point) {
|
|
356
360
|
if (code_point === 0xe7c7) return 7457;
|
|
361
|
+
|
|
357
362
|
var offset = 0;
|
|
358
363
|
var pointer_offset = 0;
|
|
359
364
|
var idx = index('gb18030-ranges');
|
|
360
365
|
var i;
|
|
361
|
-
|
|
362
366
|
for (i = 0; i < idx.length; ++i) {
|
|
363
367
|
var entry = idx[i];
|
|
364
|
-
|
|
365
368
|
if (entry[1] <= code_point) {
|
|
366
369
|
offset = entry[1];
|
|
367
370
|
pointer_offset = entry[0];
|
|
@@ -378,9 +381,9 @@ function indexShiftJISPointerFor(code_point) {
|
|
|
378
381
|
return inRange(pointer, 8272, 8835) ? null : code_point;
|
|
379
382
|
});
|
|
380
383
|
var index_ = shift_jis_index;
|
|
384
|
+
|
|
381
385
|
return index_.indexOf(code_point);
|
|
382
386
|
}
|
|
383
|
-
|
|
384
387
|
var shift_jis_index;
|
|
385
388
|
|
|
386
389
|
function indexBig5PointerFor(code_point) {
|
|
@@ -395,30 +398,35 @@ function indexBig5PointerFor(code_point) {
|
|
|
395
398
|
|
|
396
399
|
return indexPointerFor(code_point, index_);
|
|
397
400
|
}
|
|
398
|
-
|
|
399
401
|
var big5_index_no_hkscs;
|
|
402
|
+
|
|
400
403
|
var DEFAULT_ENCODING = 'utf-8';
|
|
401
404
|
|
|
402
405
|
function TextDecoder(label, options) {
|
|
403
406
|
if (!(this instanceof TextDecoder)) throw TypeError("Called as a function. Did you forget 'new'?");
|
|
404
407
|
label = label !== undefined ? String(label) : DEFAULT_ENCODING;
|
|
405
408
|
options = ToDictionary(options);
|
|
409
|
+
|
|
406
410
|
this._encoding = null;
|
|
407
411
|
this._decoder = null;
|
|
408
412
|
this._ignoreBOM = false;
|
|
409
413
|
this._BOMseen = false;
|
|
410
414
|
this._error_mode = 'replacement';
|
|
411
415
|
this._do_not_flush = false;
|
|
416
|
+
|
|
412
417
|
var encoding = getEncoding(label);
|
|
413
|
-
if (encoding === null || encoding.name === 'replacement') throw RangeError('Unknown encoding: ' + label);
|
|
414
418
|
|
|
419
|
+
if (encoding === null || encoding.name === 'replacement') throw RangeError('Unknown encoding: ' + label);
|
|
415
420
|
if (!decoders[encoding.name]) {
|
|
416
421
|
throw Error('Decoder not present.' + ' Did you forget to include encoding-indexes.js first?');
|
|
417
422
|
}
|
|
418
423
|
|
|
419
424
|
var dec = this;
|
|
425
|
+
|
|
420
426
|
dec._encoding = encoding;
|
|
427
|
+
|
|
421
428
|
if (Boolean(options['fatal'])) dec._error_mode = 'fatal';
|
|
429
|
+
|
|
422
430
|
if (Boolean(options['ignoreBOM'])) dec._ignoreBOM = true;
|
|
423
431
|
|
|
424
432
|
if (!Object.defineProperty) {
|
|
@@ -429,18 +437,19 @@ function TextDecoder(label, options) {
|
|
|
429
437
|
|
|
430
438
|
return dec;
|
|
431
439
|
}
|
|
432
|
-
|
|
433
440
|
if (Object.defineProperty) {
|
|
434
441
|
Object.defineProperty(TextDecoder.prototype, 'encoding', {
|
|
435
442
|
get: function get() {
|
|
436
443
|
return this._encoding.name.toLowerCase();
|
|
437
444
|
}
|
|
438
445
|
});
|
|
446
|
+
|
|
439
447
|
Object.defineProperty(TextDecoder.prototype, 'fatal', {
|
|
440
448
|
get: function get() {
|
|
441
449
|
return this._error_mode === 'fatal';
|
|
442
450
|
}
|
|
443
451
|
});
|
|
452
|
+
|
|
444
453
|
Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', {
|
|
445
454
|
get: function get() {
|
|
446
455
|
return this._ignoreBOM;
|
|
@@ -450,7 +459,6 @@ if (Object.defineProperty) {
|
|
|
450
459
|
|
|
451
460
|
TextDecoder.prototype.decode = function decode(input, options) {
|
|
452
461
|
var bytes;
|
|
453
|
-
|
|
454
462
|
if ((0, _typeof2.default)(input) === 'object' && input instanceof ArrayBuffer) {
|
|
455
463
|
bytes = new Uint8Array(input);
|
|
456
464
|
} else if ((0, _typeof2.default)(input) === 'object' && 'buffer' in input && input.buffer instanceof ArrayBuffer) {
|
|
@@ -458,7 +466,6 @@ TextDecoder.prototype.decode = function decode(input, options) {
|
|
|
458
466
|
} else {
|
|
459
467
|
bytes = new Uint8Array(0);
|
|
460
468
|
}
|
|
461
|
-
|
|
462
469
|
options = ToDictionary(options);
|
|
463
470
|
|
|
464
471
|
if (!this._do_not_flush) {
|
|
@@ -469,21 +476,26 @@ TextDecoder.prototype.decode = function decode(input, options) {
|
|
|
469
476
|
}
|
|
470
477
|
|
|
471
478
|
this._do_not_flush = Boolean(options['stream']);
|
|
479
|
+
|
|
472
480
|
var input_stream = new Stream(bytes);
|
|
481
|
+
|
|
473
482
|
var output = [];
|
|
483
|
+
|
|
474
484
|
var result;
|
|
475
485
|
|
|
476
486
|
while (true) {
|
|
477
487
|
var token = input_stream.read();
|
|
488
|
+
|
|
478
489
|
if (token === end_of_stream) break;
|
|
490
|
+
|
|
479
491
|
result = this._decoder.handler(input_stream, token);
|
|
480
|
-
if (result === finished) break;
|
|
481
492
|
|
|
493
|
+
if (result === finished) break;
|
|
482
494
|
if (result !== null) {
|
|
483
495
|
if (Array.isArray(result)) output.push.apply(output, result);else output.push(result);
|
|
484
496
|
}
|
|
485
|
-
}
|
|
486
497
|
|
|
498
|
+
}
|
|
487
499
|
if (!this._do_not_flush) {
|
|
488
500
|
do {
|
|
489
501
|
result = this._decoder.handler(input_stream, input_stream.read());
|
|
@@ -491,57 +503,56 @@ TextDecoder.prototype.decode = function decode(input, options) {
|
|
|
491
503
|
if (result === null) continue;
|
|
492
504
|
if (Array.isArray(result)) output.push.apply(output, result);else output.push(result);
|
|
493
505
|
} while (!input_stream.endOfStream());
|
|
494
|
-
|
|
495
506
|
this._decoder = null;
|
|
496
507
|
}
|
|
497
508
|
|
|
498
509
|
function serializeStream(stream) {
|
|
510
|
+
|
|
499
511
|
if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) && !this._ignoreBOM && !this._BOMseen) {
|
|
500
512
|
if (stream.length > 0 && stream[0] === 0xfeff) {
|
|
501
513
|
this._BOMseen = true;
|
|
502
514
|
stream.shift();
|
|
503
515
|
} else if (stream.length > 0) {
|
|
504
516
|
this._BOMseen = true;
|
|
505
|
-
} else {
|
|
517
|
+
} else {
|
|
518
|
+
}
|
|
506
519
|
}
|
|
507
|
-
|
|
508
520
|
return codePointsToString(stream);
|
|
509
521
|
}
|
|
510
|
-
|
|
511
522
|
return serializeStream.call(this, output);
|
|
512
523
|
};
|
|
513
524
|
|
|
514
525
|
function TextEncoder(label, options) {
|
|
515
526
|
if (!(this instanceof TextEncoder)) throw TypeError("Called as a function. Did you forget 'new'?");
|
|
516
527
|
options = ToDictionary(options);
|
|
528
|
+
|
|
517
529
|
this._encoding = null;
|
|
518
530
|
this._encoder = null;
|
|
531
|
+
|
|
519
532
|
this._do_not_flush = false;
|
|
520
533
|
this._fatal = Boolean(options['fatal']) ? 'fatal' : 'replacement';
|
|
534
|
+
|
|
521
535
|
var enc = this;
|
|
522
536
|
|
|
523
537
|
if (Boolean(options['NONSTANDARD_allowLegacyEncoding'])) {
|
|
524
538
|
label = label !== undefined ? String(label) : DEFAULT_ENCODING;
|
|
525
539
|
var encoding = getEncoding(label);
|
|
526
540
|
if (encoding === null || encoding.name === 'replacement') throw RangeError('Unknown encoding: ' + label);
|
|
527
|
-
|
|
528
541
|
if (!encoders[encoding.name]) {
|
|
529
542
|
throw Error('Encoder not present.' + ' Did you forget to include encoding-indexes.js first?');
|
|
530
543
|
}
|
|
531
|
-
|
|
532
544
|
enc._encoding = encoding;
|
|
533
545
|
} else {
|
|
534
546
|
enc._encoding = getEncoding('utf-8');
|
|
535
|
-
|
|
536
547
|
if (label !== undefined && 'console' in global) {
|
|
537
548
|
console.warn('TextEncoder constructor called with encoding label, ' + 'which is ignored.');
|
|
538
549
|
}
|
|
539
550
|
}
|
|
540
551
|
|
|
541
552
|
if (!Object.defineProperty) this.encoding = enc._encoding.name.toLowerCase();
|
|
553
|
+
|
|
542
554
|
return enc;
|
|
543
555
|
}
|
|
544
|
-
|
|
545
556
|
if (Object.defineProperty) {
|
|
546
557
|
Object.defineProperty(TextEncoder.prototype, 'encoding', {
|
|
547
558
|
get: function get() {
|
|
@@ -553,14 +564,17 @@ if (Object.defineProperty) {
|
|
|
553
564
|
TextEncoder.prototype.encode = function encode(opt_string, options) {
|
|
554
565
|
opt_string = opt_string === undefined ? '' : String(opt_string);
|
|
555
566
|
options = ToDictionary(options);
|
|
567
|
+
|
|
556
568
|
if (!this._do_not_flush) this._encoder = encoders[this._encoding.name]({
|
|
557
569
|
fatal: this._fatal === 'fatal'
|
|
558
570
|
});
|
|
559
571
|
this._do_not_flush = Boolean(options['stream']);
|
|
572
|
+
|
|
560
573
|
var input = new Stream(stringToCodePoints(opt_string));
|
|
574
|
+
|
|
561
575
|
var output = [];
|
|
562
|
-
var result;
|
|
563
576
|
|
|
577
|
+
var result;
|
|
564
578
|
while (true) {
|
|
565
579
|
var token = input.read();
|
|
566
580
|
if (token === end_of_stream) break;
|
|
@@ -568,27 +582,25 @@ TextEncoder.prototype.encode = function encode(opt_string, options) {
|
|
|
568
582
|
if (result === finished) break;
|
|
569
583
|
if (Array.isArray(result)) output.push.apply(output, result);else output.push(result);
|
|
570
584
|
}
|
|
571
|
-
|
|
572
585
|
if (!this._do_not_flush) {
|
|
573
586
|
while (true) {
|
|
574
587
|
result = this._encoder.handler(input, input.read());
|
|
575
588
|
if (result === finished) break;
|
|
576
589
|
if (Array.isArray(result)) output.push.apply(output, result);else output.push(result);
|
|
577
590
|
}
|
|
578
|
-
|
|
579
591
|
this._encoder = null;
|
|
580
592
|
}
|
|
581
|
-
|
|
582
593
|
return new Uint8Array(output);
|
|
583
594
|
};
|
|
584
595
|
|
|
585
596
|
function UTF8Decoder(options) {
|
|
586
597
|
var fatal = options.fatal;
|
|
598
|
+
|
|
587
599
|
var utf8_code_point = 0,
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
600
|
+
utf8_bytes_seen = 0,
|
|
601
|
+
utf8_bytes_needed = 0,
|
|
602
|
+
utf8_lower_boundary = 0x80,
|
|
603
|
+
utf8_upper_boundary = 0xbf;
|
|
592
604
|
|
|
593
605
|
this.handler = function (stream, bite) {
|
|
594
606
|
if (bite === end_of_stream && utf8_bytes_needed !== 0) {
|
|
@@ -601,22 +613,31 @@ function UTF8Decoder(options) {
|
|
|
601
613
|
if (utf8_bytes_needed === 0) {
|
|
602
614
|
if (inRange(bite, 0x00, 0x7f)) {
|
|
603
615
|
return bite;
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
else if (inRange(bite, 0xc2, 0xdf)) {
|
|
619
|
+
utf8_bytes_needed = 1;
|
|
620
|
+
|
|
621
|
+
utf8_code_point = bite & 0x1f;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
else if (inRange(bite, 0xe0, 0xef)) {
|
|
625
|
+
if (bite === 0xe0) utf8_lower_boundary = 0xa0;
|
|
626
|
+
if (bite === 0xed) utf8_upper_boundary = 0x9f;
|
|
627
|
+
utf8_bytes_needed = 2;
|
|
628
|
+
utf8_code_point = bite & 0xf;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
else if (inRange(bite, 0xf0, 0xf4)) {
|
|
632
|
+
if (bite === 0xf0) utf8_lower_boundary = 0x90;
|
|
633
|
+
if (bite === 0xf4) utf8_upper_boundary = 0x8f;
|
|
634
|
+
utf8_bytes_needed = 3;
|
|
635
|
+
utf8_code_point = bite & 0x7;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
else {
|
|
639
|
+
return decoderError(fatal);
|
|
640
|
+
}
|
|
620
641
|
|
|
621
642
|
return null;
|
|
622
643
|
}
|
|
@@ -625,45 +646,57 @@ function UTF8Decoder(options) {
|
|
|
625
646
|
utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
|
|
626
647
|
utf8_lower_boundary = 0x80;
|
|
627
648
|
utf8_upper_boundary = 0xbf;
|
|
649
|
+
|
|
628
650
|
stream.prepend(bite);
|
|
651
|
+
|
|
629
652
|
return decoderError(fatal);
|
|
630
653
|
}
|
|
631
654
|
|
|
632
655
|
utf8_lower_boundary = 0x80;
|
|
633
656
|
utf8_upper_boundary = 0xbf;
|
|
657
|
+
|
|
634
658
|
utf8_code_point = utf8_code_point << 6 | bite & 0x3f;
|
|
659
|
+
|
|
635
660
|
utf8_bytes_seen += 1;
|
|
661
|
+
|
|
636
662
|
if (utf8_bytes_seen !== utf8_bytes_needed) return null;
|
|
663
|
+
|
|
637
664
|
var code_point = utf8_code_point;
|
|
665
|
+
|
|
638
666
|
utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
|
|
667
|
+
|
|
639
668
|
return code_point;
|
|
640
669
|
};
|
|
641
670
|
}
|
|
642
671
|
|
|
643
672
|
function UTF8Encoder(options) {
|
|
644
673
|
var fatal = options.fatal;
|
|
645
|
-
|
|
646
674
|
this.handler = function (stream, code_point) {
|
|
647
675
|
if (code_point === end_of_stream) return finished;
|
|
676
|
+
|
|
648
677
|
if (isASCIICodePoint(code_point)) return code_point;
|
|
649
|
-
var count, offset;
|
|
650
678
|
|
|
679
|
+
var count, offset;
|
|
651
680
|
if (inRange(code_point, 0x0080, 0x07ff)) {
|
|
652
681
|
count = 1;
|
|
653
682
|
offset = 0xc0;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
683
|
+
}
|
|
684
|
+
else if (inRange(code_point, 0x0800, 0xffff)) {
|
|
685
|
+
count = 2;
|
|
686
|
+
offset = 0xe0;
|
|
687
|
+
}
|
|
688
|
+
else if (inRange(code_point, 0x10000, 0x10ffff)) {
|
|
689
|
+
count = 3;
|
|
690
|
+
offset = 0xf0;
|
|
691
|
+
}
|
|
661
692
|
|
|
662
693
|
var bytes = [(code_point >> 6 * count) + offset];
|
|
663
694
|
|
|
664
695
|
while (count > 0) {
|
|
665
696
|
var temp = code_point >> 6 * (count - 1);
|
|
697
|
+
|
|
666
698
|
bytes.push(0x80 | temp & 0x3f);
|
|
699
|
+
|
|
667
700
|
count -= 1;
|
|
668
701
|
}
|
|
669
702
|
|
|
@@ -674,35 +707,39 @@ function UTF8Encoder(options) {
|
|
|
674
707
|
encoders['UTF-8'] = function (options) {
|
|
675
708
|
return new UTF8Encoder(options);
|
|
676
709
|
};
|
|
677
|
-
|
|
678
710
|
decoders['UTF-8'] = function (options) {
|
|
679
711
|
return new UTF8Decoder(options);
|
|
680
712
|
};
|
|
681
713
|
|
|
682
714
|
function SingleByteDecoder(index, options) {
|
|
683
715
|
var fatal = options.fatal;
|
|
684
|
-
|
|
685
716
|
this.handler = function (stream, bite) {
|
|
686
717
|
if (bite === end_of_stream) return finished;
|
|
718
|
+
|
|
687
719
|
if (isASCIIByte(bite)) return bite;
|
|
720
|
+
|
|
688
721
|
var code_point = index[bite - 0x80];
|
|
722
|
+
|
|
689
723
|
if (code_point === null) return decoderError(fatal);
|
|
724
|
+
|
|
690
725
|
return code_point;
|
|
691
726
|
};
|
|
692
727
|
}
|
|
693
728
|
|
|
694
729
|
function SingleByteEncoder(index, options) {
|
|
695
730
|
var fatal = options.fatal;
|
|
696
|
-
|
|
697
731
|
this.handler = function (stream, code_point) {
|
|
698
732
|
if (code_point === end_of_stream) return finished;
|
|
733
|
+
|
|
699
734
|
if (isASCIICodePoint(code_point)) return code_point;
|
|
735
|
+
|
|
700
736
|
var pointer = indexPointerFor(code_point, index);
|
|
737
|
+
|
|
701
738
|
if (pointer === null) encoderError(code_point);
|
|
739
|
+
|
|
702
740
|
return pointer + 0x80;
|
|
703
741
|
};
|
|
704
742
|
}
|
|
705
|
-
|
|
706
743
|
(function () {
|
|
707
744
|
if (!('encoding-indexes' in global)) return;
|
|
708
745
|
encodings.forEach(function (category) {
|
|
@@ -710,11 +747,9 @@ function SingleByteEncoder(index, options) {
|
|
|
710
747
|
category.encodings.forEach(function (encoding) {
|
|
711
748
|
var name = encoding.name;
|
|
712
749
|
var idx = index(name.toLowerCase());
|
|
713
|
-
|
|
714
750
|
decoders[name] = function (options) {
|
|
715
751
|
return new SingleByteDecoder(idx, options);
|
|
716
752
|
};
|
|
717
|
-
|
|
718
753
|
encoders[name] = function (options) {
|
|
719
754
|
return new SingleByteEncoder(idx, options);
|
|
720
755
|
};
|
|
@@ -733,31 +768,27 @@ encoders['GBK'] = function (options) {
|
|
|
733
768
|
function GB18030Decoder(options) {
|
|
734
769
|
var fatal = options.fatal;
|
|
735
770
|
var gb18030_first = 0x00,
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
771
|
+
gb18030_second = 0x00,
|
|
772
|
+
gb18030_third = 0x00;
|
|
739
773
|
this.handler = function (stream, bite) {
|
|
740
774
|
if (bite === end_of_stream && gb18030_first === 0x00 && gb18030_second === 0x00 && gb18030_third === 0x00) {
|
|
741
775
|
return finished;
|
|
742
776
|
}
|
|
743
|
-
|
|
744
777
|
if (bite === end_of_stream && (gb18030_first !== 0x00 || gb18030_second !== 0x00 || gb18030_third !== 0x00)) {
|
|
745
778
|
gb18030_first = 0x00;
|
|
746
779
|
gb18030_second = 0x00;
|
|
747
780
|
gb18030_third = 0x00;
|
|
748
781
|
decoderError(fatal);
|
|
749
782
|
}
|
|
750
|
-
|
|
751
783
|
var code_point;
|
|
752
|
-
|
|
753
784
|
if (gb18030_third !== 0x00) {
|
|
754
785
|
code_point = null;
|
|
755
|
-
|
|
756
786
|
if (inRange(bite, 0x30, 0x39)) {
|
|
757
787
|
code_point = indexGB18030RangesCodePointFor((((gb18030_first - 0x81) * 10 + gb18030_second - 0x30) * 126 + gb18030_third - 0x81) * 10 + bite - 0x30);
|
|
758
788
|
}
|
|
759
789
|
|
|
760
790
|
var buffer = [gb18030_second, gb18030_third, bite];
|
|
791
|
+
|
|
761
792
|
gb18030_first = 0x00;
|
|
762
793
|
gb18030_second = 0x00;
|
|
763
794
|
gb18030_third = 0x00;
|
|
@@ -791,15 +822,22 @@ function GB18030Decoder(options) {
|
|
|
791
822
|
var lead = gb18030_first;
|
|
792
823
|
var pointer = null;
|
|
793
824
|
gb18030_first = 0x00;
|
|
825
|
+
|
|
794
826
|
var offset = bite < 0x7f ? 0x40 : 0x41;
|
|
827
|
+
|
|
795
828
|
if (inRange(bite, 0x40, 0x7e) || inRange(bite, 0x80, 0xfe)) pointer = (lead - 0x81) * 190 + (bite - offset);
|
|
829
|
+
|
|
796
830
|
code_point = pointer === null ? null : indexCodePointFor(pointer, index('gb18030'));
|
|
831
|
+
|
|
797
832
|
if (code_point === null && isASCIIByte(bite)) stream.prepend(bite);
|
|
833
|
+
|
|
798
834
|
if (code_point === null) return decoderError(fatal);
|
|
835
|
+
|
|
799
836
|
return code_point;
|
|
800
837
|
}
|
|
801
838
|
|
|
802
839
|
if (isASCIIByte(bite)) return bite;
|
|
840
|
+
|
|
803
841
|
if (bite === 0x80) return 0x20ac;
|
|
804
842
|
|
|
805
843
|
if (inRange(bite, 0x81, 0xfe)) {
|
|
@@ -813,29 +851,43 @@ function GB18030Decoder(options) {
|
|
|
813
851
|
|
|
814
852
|
function GB18030Encoder(options, gbk_flag) {
|
|
815
853
|
var fatal = options.fatal;
|
|
816
|
-
|
|
817
854
|
this.handler = function (stream, code_point) {
|
|
818
855
|
if (code_point === end_of_stream) return finished;
|
|
856
|
+
|
|
819
857
|
if (isASCIICodePoint(code_point)) return code_point;
|
|
858
|
+
|
|
820
859
|
if (code_point === 0xe5e5) return encoderError(code_point);
|
|
860
|
+
|
|
821
861
|
if (gbk_flag && code_point === 0x20ac) return 0x80;
|
|
862
|
+
|
|
822
863
|
var pointer = indexPointerFor(code_point, index('gb18030'));
|
|
823
864
|
|
|
824
865
|
if (pointer !== null) {
|
|
825
866
|
var lead = floor(pointer / 190) + 0x81;
|
|
867
|
+
|
|
826
868
|
var trail = pointer % 190;
|
|
869
|
+
|
|
827
870
|
var offset = trail < 0x3f ? 0x40 : 0x41;
|
|
871
|
+
|
|
828
872
|
return [lead, trail + offset];
|
|
829
873
|
}
|
|
830
874
|
|
|
831
875
|
if (gbk_flag) return encoderError(code_point);
|
|
876
|
+
|
|
832
877
|
pointer = indexGB18030RangesPointerFor(code_point);
|
|
878
|
+
|
|
833
879
|
var byte1 = floor(pointer / 10 / 126 / 10);
|
|
880
|
+
|
|
834
881
|
pointer = pointer - byte1 * 10 * 126 * 10;
|
|
882
|
+
|
|
835
883
|
var byte2 = floor(pointer / 10 / 126);
|
|
884
|
+
|
|
836
885
|
pointer = pointer - byte2 * 10 * 126;
|
|
886
|
+
|
|
837
887
|
var byte3 = floor(pointer / 10);
|
|
888
|
+
|
|
838
889
|
var byte4 = pointer - byte3 * 10;
|
|
890
|
+
|
|
839
891
|
return [byte1 + 0x81, byte2 + 0x30, byte3 + 0x81, byte4 + 0x30];
|
|
840
892
|
};
|
|
841
893
|
}
|
|
@@ -843,7 +895,6 @@ function GB18030Encoder(options, gbk_flag) {
|
|
|
843
895
|
encoders['gb18030'] = function (options) {
|
|
844
896
|
return new GB18030Encoder(options);
|
|
845
897
|
};
|
|
846
|
-
|
|
847
898
|
decoders['gb18030'] = function (options) {
|
|
848
899
|
return new GB18030Decoder(options);
|
|
849
900
|
};
|
|
@@ -864,26 +915,28 @@ function Big5Decoder(options) {
|
|
|
864
915
|
var lead = Big5_lead;
|
|
865
916
|
var pointer = null;
|
|
866
917
|
Big5_lead = 0x00;
|
|
918
|
+
|
|
867
919
|
var offset = bite < 0x7f ? 0x40 : 0x62;
|
|
920
|
+
|
|
868
921
|
if (inRange(bite, 0x40, 0x7e) || inRange(bite, 0xa1, 0xfe)) pointer = (lead - 0x81) * 157 + (bite - offset);
|
|
869
922
|
|
|
870
923
|
switch (pointer) {
|
|
871
924
|
case 1133:
|
|
872
925
|
return [0x00ca, 0x0304];
|
|
873
|
-
|
|
874
926
|
case 1135:
|
|
875
927
|
return [0x00ca, 0x030c];
|
|
876
|
-
|
|
877
928
|
case 1164:
|
|
878
929
|
return [0x00ea, 0x0304];
|
|
879
|
-
|
|
880
930
|
case 1166:
|
|
881
931
|
return [0x00ea, 0x030c];
|
|
882
932
|
}
|
|
883
933
|
|
|
884
934
|
var code_point = pointer === null ? null : indexCodePointFor(pointer, index('big5'));
|
|
935
|
+
|
|
885
936
|
if (code_point === null && isASCIIByte(bite)) stream.prepend(bite);
|
|
937
|
+
|
|
886
938
|
if (code_point === null) return decoderError(fatal);
|
|
939
|
+
|
|
887
940
|
return code_point;
|
|
888
941
|
}
|
|
889
942
|
|
|
@@ -900,16 +953,23 @@ function Big5Decoder(options) {
|
|
|
900
953
|
|
|
901
954
|
function Big5Encoder(options) {
|
|
902
955
|
var fatal = options.fatal;
|
|
903
|
-
|
|
904
956
|
this.handler = function (stream, code_point) {
|
|
905
957
|
if (code_point === end_of_stream) return finished;
|
|
958
|
+
|
|
906
959
|
if (isASCIICodePoint(code_point)) return code_point;
|
|
960
|
+
|
|
907
961
|
var pointer = indexBig5PointerFor(code_point);
|
|
962
|
+
|
|
908
963
|
if (pointer === null) return encoderError(code_point);
|
|
964
|
+
|
|
909
965
|
var lead = floor(pointer / 157) + 0x81;
|
|
966
|
+
|
|
910
967
|
if (lead < 0xa1) return encoderError(code_point);
|
|
968
|
+
|
|
911
969
|
var trail = pointer % 157;
|
|
970
|
+
|
|
912
971
|
var offset = trail < 0x3f ? 0x40 : 0x62;
|
|
972
|
+
|
|
913
973
|
return [lead, trail + offset];
|
|
914
974
|
};
|
|
915
975
|
}
|
|
@@ -917,15 +977,15 @@ function Big5Encoder(options) {
|
|
|
917
977
|
encoders['Big5'] = function (options) {
|
|
918
978
|
return new Big5Encoder(options);
|
|
919
979
|
};
|
|
920
|
-
|
|
921
980
|
decoders['Big5'] = function (options) {
|
|
922
981
|
return new Big5Decoder(options);
|
|
923
982
|
};
|
|
924
983
|
|
|
925
984
|
function EUCJPDecoder(options) {
|
|
926
985
|
var fatal = options.fatal;
|
|
986
|
+
|
|
927
987
|
var eucjp_jis0212_flag = false,
|
|
928
|
-
|
|
988
|
+
eucjp_lead = 0x00;
|
|
929
989
|
|
|
930
990
|
this.handler = function (stream, bite) {
|
|
931
991
|
if (bite === end_of_stream && eucjp_lead !== 0x00) {
|
|
@@ -949,6 +1009,7 @@ function EUCJPDecoder(options) {
|
|
|
949
1009
|
if (eucjp_lead !== 0x00) {
|
|
950
1010
|
var lead = eucjp_lead;
|
|
951
1011
|
eucjp_lead = 0x00;
|
|
1012
|
+
|
|
952
1013
|
var code_point = null;
|
|
953
1014
|
|
|
954
1015
|
if (inRange(lead, 0xa1, 0xfe) && inRange(bite, 0xa1, 0xfe)) {
|
|
@@ -956,8 +1017,11 @@ function EUCJPDecoder(options) {
|
|
|
956
1017
|
}
|
|
957
1018
|
|
|
958
1019
|
eucjp_jis0212_flag = false;
|
|
1020
|
+
|
|
959
1021
|
if (!inRange(bite, 0xa1, 0xfe)) stream.prepend(bite);
|
|
1022
|
+
|
|
960
1023
|
if (code_point === null) return decoderError(fatal);
|
|
1024
|
+
|
|
961
1025
|
return code_point;
|
|
962
1026
|
}
|
|
963
1027
|
|
|
@@ -974,18 +1038,27 @@ function EUCJPDecoder(options) {
|
|
|
974
1038
|
|
|
975
1039
|
function EUCJPEncoder(options) {
|
|
976
1040
|
var fatal = options.fatal;
|
|
977
|
-
|
|
978
1041
|
this.handler = function (stream, code_point) {
|
|
979
1042
|
if (code_point === end_of_stream) return finished;
|
|
1043
|
+
|
|
980
1044
|
if (isASCIICodePoint(code_point)) return code_point;
|
|
1045
|
+
|
|
981
1046
|
if (code_point === 0x00a5) return 0x5c;
|
|
1047
|
+
|
|
982
1048
|
if (code_point === 0x203e) return 0x7e;
|
|
1049
|
+
|
|
983
1050
|
if (inRange(code_point, 0xff61, 0xff9f)) return [0x8e, code_point - 0xff61 + 0xa1];
|
|
1051
|
+
|
|
984
1052
|
if (code_point === 0x2212) code_point = 0xff0d;
|
|
1053
|
+
|
|
985
1054
|
var pointer = indexPointerFor(code_point, index('jis0208'));
|
|
1055
|
+
|
|
986
1056
|
if (pointer === null) return encoderError(code_point);
|
|
1057
|
+
|
|
987
1058
|
var lead = floor(pointer / 94) + 0xa1;
|
|
1059
|
+
|
|
988
1060
|
var trail = pointer % 94 + 0xa1;
|
|
1061
|
+
|
|
989
1062
|
return [lead, trail];
|
|
990
1063
|
};
|
|
991
1064
|
}
|
|
@@ -993,7 +1066,6 @@ function EUCJPEncoder(options) {
|
|
|
993
1066
|
encoders['EUC-JP'] = function (options) {
|
|
994
1067
|
return new EUCJPEncoder(options);
|
|
995
1068
|
};
|
|
996
|
-
|
|
997
1069
|
decoders['EUC-JP'] = function (options) {
|
|
998
1070
|
return new EUCJPDecoder(options);
|
|
999
1071
|
};
|
|
@@ -1010,14 +1082,14 @@ function ISO2022JPDecoder(options) {
|
|
|
1010
1082
|
Escape: 6
|
|
1011
1083
|
};
|
|
1012
1084
|
var iso2022jp_decoder_state = states.ASCII,
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1085
|
+
iso2022jp_decoder_output_state = states.ASCII,
|
|
1086
|
+
iso2022jp_lead = 0x00,
|
|
1087
|
+
iso2022jp_output_flag = false;
|
|
1017
1088
|
this.handler = function (stream, bite) {
|
|
1018
1089
|
switch (iso2022jp_decoder_state) {
|
|
1019
1090
|
default:
|
|
1020
1091
|
case states.ASCII:
|
|
1092
|
+
|
|
1021
1093
|
if (bite === 0x1b) {
|
|
1022
1094
|
iso2022jp_decoder_state = states.EscapeStart;
|
|
1023
1095
|
return null;
|
|
@@ -1034,8 +1106,8 @@ function ISO2022JPDecoder(options) {
|
|
|
1034
1106
|
|
|
1035
1107
|
iso2022jp_output_flag = false;
|
|
1036
1108
|
return decoderError(fatal);
|
|
1037
|
-
|
|
1038
1109
|
case states.Roman:
|
|
1110
|
+
|
|
1039
1111
|
if (bite === 0x1b) {
|
|
1040
1112
|
iso2022jp_decoder_state = states.EscapeStart;
|
|
1041
1113
|
return null;
|
|
@@ -1062,8 +1134,8 @@ function ISO2022JPDecoder(options) {
|
|
|
1062
1134
|
|
|
1063
1135
|
iso2022jp_output_flag = false;
|
|
1064
1136
|
return decoderError(fatal);
|
|
1065
|
-
|
|
1066
1137
|
case states.Katakana:
|
|
1138
|
+
|
|
1067
1139
|
if (bite === 0x1b) {
|
|
1068
1140
|
iso2022jp_decoder_state = states.EscapeStart;
|
|
1069
1141
|
return null;
|
|
@@ -1080,8 +1152,8 @@ function ISO2022JPDecoder(options) {
|
|
|
1080
1152
|
|
|
1081
1153
|
iso2022jp_output_flag = false;
|
|
1082
1154
|
return decoderError(fatal);
|
|
1083
|
-
|
|
1084
1155
|
case states.LeadByte:
|
|
1156
|
+
|
|
1085
1157
|
if (bite === 0x1b) {
|
|
1086
1158
|
iso2022jp_decoder_state = states.EscapeStart;
|
|
1087
1159
|
return null;
|
|
@@ -1100,8 +1172,8 @@ function ISO2022JPDecoder(options) {
|
|
|
1100
1172
|
|
|
1101
1173
|
iso2022jp_output_flag = false;
|
|
1102
1174
|
return decoderError(fatal);
|
|
1103
|
-
|
|
1104
1175
|
case states.TrailByte:
|
|
1176
|
+
|
|
1105
1177
|
if (bite === 0x1b) {
|
|
1106
1178
|
iso2022jp_decoder_state = states.EscapeStart;
|
|
1107
1179
|
return decoderError(fatal);
|
|
@@ -1109,9 +1181,13 @@ function ISO2022JPDecoder(options) {
|
|
|
1109
1181
|
|
|
1110
1182
|
if (inRange(bite, 0x21, 0x7e)) {
|
|
1111
1183
|
iso2022jp_decoder_state = states.LeadByte;
|
|
1184
|
+
|
|
1112
1185
|
var pointer = (iso2022jp_lead - 0x21) * 94 + bite - 0x21;
|
|
1186
|
+
|
|
1113
1187
|
var code_point = indexCodePointFor(pointer, index('jis0208'));
|
|
1188
|
+
|
|
1114
1189
|
if (code_point === null) return decoderError(fatal);
|
|
1190
|
+
|
|
1115
1191
|
return code_point;
|
|
1116
1192
|
}
|
|
1117
1193
|
|
|
@@ -1123,8 +1199,8 @@ function ISO2022JPDecoder(options) {
|
|
|
1123
1199
|
|
|
1124
1200
|
iso2022jp_decoder_state = states.LeadByte;
|
|
1125
1201
|
return decoderError(fatal);
|
|
1126
|
-
|
|
1127
1202
|
case states.EscapeStart:
|
|
1203
|
+
|
|
1128
1204
|
if (bite === 0x24 || bite === 0x28) {
|
|
1129
1205
|
iso2022jp_lead = bite;
|
|
1130
1206
|
iso2022jp_decoder_state = states.Escape;
|
|
@@ -1132,27 +1208,37 @@ function ISO2022JPDecoder(options) {
|
|
|
1132
1208
|
}
|
|
1133
1209
|
|
|
1134
1210
|
stream.prepend(bite);
|
|
1211
|
+
|
|
1135
1212
|
iso2022jp_output_flag = false;
|
|
1136
1213
|
iso2022jp_decoder_state = iso2022jp_decoder_output_state;
|
|
1137
1214
|
return decoderError(fatal);
|
|
1138
|
-
|
|
1139
1215
|
case states.Escape:
|
|
1216
|
+
|
|
1140
1217
|
var lead = iso2022jp_lead;
|
|
1141
1218
|
iso2022jp_lead = 0x00;
|
|
1219
|
+
|
|
1142
1220
|
var state = null;
|
|
1221
|
+
|
|
1143
1222
|
if (lead === 0x28 && bite === 0x42) state = states.ASCII;
|
|
1223
|
+
|
|
1144
1224
|
if (lead === 0x28 && bite === 0x4a) state = states.Roman;
|
|
1225
|
+
|
|
1145
1226
|
if (lead === 0x28 && bite === 0x49) state = states.Katakana;
|
|
1227
|
+
|
|
1146
1228
|
if (lead === 0x24 && (bite === 0x40 || bite === 0x42)) state = states.LeadByte;
|
|
1147
1229
|
|
|
1148
1230
|
if (state !== null) {
|
|
1149
1231
|
iso2022jp_decoder_state = iso2022jp_decoder_state = state;
|
|
1232
|
+
|
|
1150
1233
|
var output_flag = iso2022jp_output_flag;
|
|
1234
|
+
|
|
1151
1235
|
iso2022jp_output_flag = true;
|
|
1236
|
+
|
|
1152
1237
|
return !output_flag ? null : decoderError(fatal);
|
|
1153
1238
|
}
|
|
1154
1239
|
|
|
1155
1240
|
stream.prepend([lead, bite]);
|
|
1241
|
+
|
|
1156
1242
|
iso2022jp_output_flag = false;
|
|
1157
1243
|
iso2022jp_decoder_state = iso2022jp_decoder_output_state;
|
|
1158
1244
|
return decoderError(fatal);
|
|
@@ -1168,7 +1254,6 @@ function ISO2022JPEncoder(options) {
|
|
|
1168
1254
|
jis0208: 2
|
|
1169
1255
|
};
|
|
1170
1256
|
var iso2022jp_state = states.ASCII;
|
|
1171
|
-
|
|
1172
1257
|
this.handler = function (stream, code_point) {
|
|
1173
1258
|
if (code_point === end_of_stream && iso2022jp_state !== states.ASCII) {
|
|
1174
1259
|
stream.prepend(code_point);
|
|
@@ -1186,7 +1271,9 @@ function ISO2022JPEncoder(options) {
|
|
|
1186
1271
|
|
|
1187
1272
|
if (iso2022jp_state === states.Roman && (isASCIICodePoint(code_point) && code_point !== 0x005c && code_point !== 0x007e || code_point == 0x00a5 || code_point == 0x203e)) {
|
|
1188
1273
|
if (isASCIICodePoint(code_point)) return code_point;
|
|
1274
|
+
|
|
1189
1275
|
if (code_point === 0x00a5) return 0x5c;
|
|
1276
|
+
|
|
1190
1277
|
if (code_point === 0x203e) return 0x7e;
|
|
1191
1278
|
}
|
|
1192
1279
|
|
|
@@ -1203,7 +1290,9 @@ function ISO2022JPEncoder(options) {
|
|
|
1203
1290
|
}
|
|
1204
1291
|
|
|
1205
1292
|
if (code_point === 0x2212) code_point = 0xff0d;
|
|
1293
|
+
|
|
1206
1294
|
var pointer = indexPointerFor(code_point, index('jis0208'));
|
|
1295
|
+
|
|
1207
1296
|
if (pointer === null) return encoderError(code_point);
|
|
1208
1297
|
|
|
1209
1298
|
if (iso2022jp_state !== states.jis0208) {
|
|
@@ -1213,7 +1302,9 @@ function ISO2022JPEncoder(options) {
|
|
|
1213
1302
|
}
|
|
1214
1303
|
|
|
1215
1304
|
var lead = floor(pointer / 94) + 0x21;
|
|
1305
|
+
|
|
1216
1306
|
var trail = pointer % 94 + 0x21;
|
|
1307
|
+
|
|
1217
1308
|
return [lead, trail];
|
|
1218
1309
|
};
|
|
1219
1310
|
}
|
|
@@ -1221,7 +1312,6 @@ function ISO2022JPEncoder(options) {
|
|
|
1221
1312
|
encoders['ISO-2022-JP'] = function (options) {
|
|
1222
1313
|
return new ISO2022JPEncoder(options);
|
|
1223
1314
|
};
|
|
1224
|
-
|
|
1225
1315
|
decoders['ISO-2022-JP'] = function (options) {
|
|
1226
1316
|
return new ISO2022JPDecoder(options);
|
|
1227
1317
|
};
|
|
@@ -1229,7 +1319,6 @@ decoders['ISO-2022-JP'] = function (options) {
|
|
|
1229
1319
|
function ShiftJISDecoder(options) {
|
|
1230
1320
|
var fatal = options.fatal;
|
|
1231
1321
|
var Shift_JIS_lead = 0x00;
|
|
1232
|
-
|
|
1233
1322
|
this.handler = function (stream, bite) {
|
|
1234
1323
|
if (bite === end_of_stream && Shift_JIS_lead !== 0x00) {
|
|
1235
1324
|
Shift_JIS_lead = 0x00;
|
|
@@ -1242,17 +1331,26 @@ function ShiftJISDecoder(options) {
|
|
|
1242
1331
|
var lead = Shift_JIS_lead;
|
|
1243
1332
|
var pointer = null;
|
|
1244
1333
|
Shift_JIS_lead = 0x00;
|
|
1334
|
+
|
|
1245
1335
|
var offset = bite < 0x7f ? 0x40 : 0x41;
|
|
1336
|
+
|
|
1246
1337
|
var lead_offset = lead < 0xa0 ? 0x81 : 0xc1;
|
|
1338
|
+
|
|
1247
1339
|
if (inRange(bite, 0x40, 0x7e) || inRange(bite, 0x80, 0xfc)) pointer = (lead - lead_offset) * 188 + bite - offset;
|
|
1340
|
+
|
|
1248
1341
|
if (inRange(pointer, 8836, 10715)) return 0xe000 - 8836 + pointer;
|
|
1342
|
+
|
|
1249
1343
|
var code_point = pointer === null ? null : indexCodePointFor(pointer, index('jis0208'));
|
|
1344
|
+
|
|
1250
1345
|
if (code_point === null && isASCIIByte(bite)) stream.prepend(bite);
|
|
1346
|
+
|
|
1251
1347
|
if (code_point === null) return decoderError(fatal);
|
|
1348
|
+
|
|
1252
1349
|
return code_point;
|
|
1253
1350
|
}
|
|
1254
1351
|
|
|
1255
1352
|
if (isASCIIByte(bite) || bite === 0x80) return bite;
|
|
1353
|
+
|
|
1256
1354
|
if (inRange(bite, 0xa1, 0xdf)) return 0xff61 - 0xa1 + bite;
|
|
1257
1355
|
|
|
1258
1356
|
if (inRange(bite, 0x81, 0x9f) || inRange(bite, 0xe0, 0xfc)) {
|
|
@@ -1266,20 +1364,31 @@ function ShiftJISDecoder(options) {
|
|
|
1266
1364
|
|
|
1267
1365
|
function ShiftJISEncoder(options) {
|
|
1268
1366
|
var fatal = options.fatal;
|
|
1269
|
-
|
|
1270
1367
|
this.handler = function (stream, code_point) {
|
|
1271
1368
|
if (code_point === end_of_stream) return finished;
|
|
1369
|
+
|
|
1272
1370
|
if (isASCIICodePoint(code_point) || code_point === 0x0080) return code_point;
|
|
1371
|
+
|
|
1273
1372
|
if (code_point === 0x00a5) return 0x5c;
|
|
1373
|
+
|
|
1274
1374
|
if (code_point === 0x203e) return 0x7e;
|
|
1375
|
+
|
|
1275
1376
|
if (inRange(code_point, 0xff61, 0xff9f)) return code_point - 0xff61 + 0xa1;
|
|
1377
|
+
|
|
1276
1378
|
if (code_point === 0x2212) code_point = 0xff0d;
|
|
1379
|
+
|
|
1277
1380
|
var pointer = indexShiftJISPointerFor(code_point);
|
|
1381
|
+
|
|
1278
1382
|
if (pointer === null) return encoderError(code_point);
|
|
1383
|
+
|
|
1279
1384
|
var lead = floor(pointer / 188);
|
|
1385
|
+
|
|
1280
1386
|
var lead_offset = lead < 0x1f ? 0x81 : 0xc1;
|
|
1387
|
+
|
|
1281
1388
|
var trail = pointer % 188;
|
|
1389
|
+
|
|
1282
1390
|
var offset = trail < 0x3f ? 0x40 : 0x41;
|
|
1391
|
+
|
|
1283
1392
|
return [lead + lead_offset, trail + offset];
|
|
1284
1393
|
};
|
|
1285
1394
|
}
|
|
@@ -1287,15 +1396,14 @@ function ShiftJISEncoder(options) {
|
|
|
1287
1396
|
encoders['Shift_JIS'] = function (options) {
|
|
1288
1397
|
return new ShiftJISEncoder(options);
|
|
1289
1398
|
};
|
|
1290
|
-
|
|
1291
1399
|
decoders['Shift_JIS'] = function (options) {
|
|
1292
1400
|
return new ShiftJISDecoder(options);
|
|
1293
1401
|
};
|
|
1294
1402
|
|
|
1295
1403
|
function EUCKRDecoder(options) {
|
|
1296
1404
|
var fatal = options.fatal;
|
|
1297
|
-
var euckr_lead = 0x00;
|
|
1298
1405
|
|
|
1406
|
+
var euckr_lead = 0x00;
|
|
1299
1407
|
this.handler = function (stream, bite) {
|
|
1300
1408
|
if (bite === end_of_stream && euckr_lead !== 0) {
|
|
1301
1409
|
euckr_lead = 0x00;
|
|
@@ -1308,10 +1416,15 @@ function EUCKRDecoder(options) {
|
|
|
1308
1416
|
var lead = euckr_lead;
|
|
1309
1417
|
var pointer = null;
|
|
1310
1418
|
euckr_lead = 0x00;
|
|
1419
|
+
|
|
1311
1420
|
if (inRange(bite, 0x41, 0xfe)) pointer = (lead - 0x81) * 190 + (bite - 0x41);
|
|
1421
|
+
|
|
1312
1422
|
var code_point = pointer === null ? null : indexCodePointFor(pointer, index('euc-kr'));
|
|
1423
|
+
|
|
1313
1424
|
if (pointer === null && isASCIIByte(bite)) stream.prepend(bite);
|
|
1425
|
+
|
|
1314
1426
|
if (code_point === null) return decoderError(fatal);
|
|
1427
|
+
|
|
1315
1428
|
return code_point;
|
|
1316
1429
|
}
|
|
1317
1430
|
|
|
@@ -1328,14 +1441,19 @@ function EUCKRDecoder(options) {
|
|
|
1328
1441
|
|
|
1329
1442
|
function EUCKREncoder(options) {
|
|
1330
1443
|
var fatal = options.fatal;
|
|
1331
|
-
|
|
1332
1444
|
this.handler = function (stream, code_point) {
|
|
1333
1445
|
if (code_point === end_of_stream) return finished;
|
|
1446
|
+
|
|
1334
1447
|
if (isASCIICodePoint(code_point)) return code_point;
|
|
1448
|
+
|
|
1335
1449
|
var pointer = indexPointerFor(code_point, index('euc-kr'));
|
|
1450
|
+
|
|
1336
1451
|
if (pointer === null) return encoderError(code_point);
|
|
1452
|
+
|
|
1337
1453
|
var lead = floor(pointer / 190) + 0x81;
|
|
1454
|
+
|
|
1338
1455
|
var trail = pointer % 190 + 0x41;
|
|
1456
|
+
|
|
1339
1457
|
return [lead, trail];
|
|
1340
1458
|
};
|
|
1341
1459
|
}
|
|
@@ -1343,14 +1461,15 @@ function EUCKREncoder(options) {
|
|
|
1343
1461
|
encoders['EUC-KR'] = function (options) {
|
|
1344
1462
|
return new EUCKREncoder(options);
|
|
1345
1463
|
};
|
|
1346
|
-
|
|
1347
1464
|
decoders['EUC-KR'] = function (options) {
|
|
1348
1465
|
return new EUCKRDecoder(options);
|
|
1349
1466
|
};
|
|
1350
1467
|
|
|
1351
1468
|
function convertCodeUnitToBytes(code_unit, utf16be) {
|
|
1352
1469
|
var byte1 = code_unit >> 8;
|
|
1470
|
+
|
|
1353
1471
|
var byte2 = code_unit & 0x00ff;
|
|
1472
|
+
|
|
1354
1473
|
if (utf16be) return [byte1, byte2];
|
|
1355
1474
|
return [byte2, byte1];
|
|
1356
1475
|
}
|
|
@@ -1358,8 +1477,7 @@ function convertCodeUnitToBytes(code_unit, utf16be) {
|
|
|
1358
1477
|
function UTF16Decoder(utf16_be, options) {
|
|
1359
1478
|
var fatal = options.fatal;
|
|
1360
1479
|
var utf16_lead_byte = null,
|
|
1361
|
-
|
|
1362
|
-
|
|
1480
|
+
utf16_lead_surrogate = null;
|
|
1363
1481
|
this.handler = function (stream, bite) {
|
|
1364
1482
|
if (bite === end_of_stream && (utf16_lead_byte !== null || utf16_lead_surrogate !== null)) {
|
|
1365
1483
|
return decoderError(fatal);
|
|
@@ -1375,13 +1493,11 @@ function UTF16Decoder(utf16_be, options) {
|
|
|
1375
1493
|
}
|
|
1376
1494
|
|
|
1377
1495
|
var code_unit;
|
|
1378
|
-
|
|
1379
1496
|
if (utf16_be) {
|
|
1380
1497
|
code_unit = (utf16_lead_byte << 8) + bite;
|
|
1381
1498
|
} else {
|
|
1382
1499
|
code_unit = (bite << 8) + utf16_lead_byte;
|
|
1383
1500
|
}
|
|
1384
|
-
|
|
1385
1501
|
utf16_lead_byte = null;
|
|
1386
1502
|
|
|
1387
1503
|
if (utf16_lead_surrogate !== null) {
|
|
@@ -1402,18 +1518,22 @@ function UTF16Decoder(utf16_be, options) {
|
|
|
1402
1518
|
}
|
|
1403
1519
|
|
|
1404
1520
|
if (inRange(code_unit, 0xdc00, 0xdfff)) return decoderError(fatal);
|
|
1521
|
+
|
|
1405
1522
|
return code_unit;
|
|
1406
1523
|
};
|
|
1407
1524
|
}
|
|
1408
1525
|
|
|
1409
1526
|
function UTF16Encoder(utf16_be, options) {
|
|
1410
1527
|
var fatal = options.fatal;
|
|
1411
|
-
|
|
1412
1528
|
this.handler = function (stream, code_point) {
|
|
1413
1529
|
if (code_point === end_of_stream) return finished;
|
|
1530
|
+
|
|
1414
1531
|
if (inRange(code_point, 0x0000, 0xffff)) return convertCodeUnitToBytes(code_point, utf16_be);
|
|
1532
|
+
|
|
1415
1533
|
var lead = convertCodeUnitToBytes((code_point - 0x10000 >> 10) + 0xd800, utf16_be);
|
|
1534
|
+
|
|
1416
1535
|
var trail = convertCodeUnitToBytes((code_point - 0x10000 & 0x3ff) + 0xdc00, utf16_be);
|
|
1536
|
+
|
|
1417
1537
|
return lead.concat(trail);
|
|
1418
1538
|
};
|
|
1419
1539
|
}
|
|
@@ -1421,7 +1541,6 @@ function UTF16Encoder(utf16_be, options) {
|
|
|
1421
1541
|
encoders['UTF-16BE'] = function (options) {
|
|
1422
1542
|
return new UTF16Encoder(true, options);
|
|
1423
1543
|
};
|
|
1424
|
-
|
|
1425
1544
|
decoders['UTF-16BE'] = function (options) {
|
|
1426
1545
|
return new UTF16Decoder(true, options);
|
|
1427
1546
|
};
|
|
@@ -1429,28 +1548,30 @@ decoders['UTF-16BE'] = function (options) {
|
|
|
1429
1548
|
encoders['UTF-16LE'] = function (options) {
|
|
1430
1549
|
return new UTF16Encoder(false, options);
|
|
1431
1550
|
};
|
|
1432
|
-
|
|
1433
1551
|
decoders['UTF-16LE'] = function (options) {
|
|
1434
1552
|
return new UTF16Decoder(false, options);
|
|
1435
1553
|
};
|
|
1436
1554
|
|
|
1437
1555
|
function XUserDefinedDecoder(options) {
|
|
1438
1556
|
var fatal = options.fatal;
|
|
1439
|
-
|
|
1440
1557
|
this.handler = function (stream, bite) {
|
|
1441
1558
|
if (bite === end_of_stream) return finished;
|
|
1559
|
+
|
|
1442
1560
|
if (isASCIIByte(bite)) return bite;
|
|
1561
|
+
|
|
1443
1562
|
return 0xf780 + bite - 0x80;
|
|
1444
1563
|
};
|
|
1445
1564
|
}
|
|
1446
1565
|
|
|
1447
1566
|
function XUserDefinedEncoder(options) {
|
|
1448
1567
|
var fatal = options.fatal;
|
|
1449
|
-
|
|
1450
1568
|
this.handler = function (stream, code_point) {
|
|
1451
1569
|
if (code_point === end_of_stream) return finished;
|
|
1570
|
+
|
|
1452
1571
|
if (isASCIICodePoint(code_point)) return code_point;
|
|
1572
|
+
|
|
1453
1573
|
if (inRange(code_point, 0xf780, 0xf7ff)) return code_point - 0xf780 + 0x80;
|
|
1574
|
+
|
|
1454
1575
|
return encoderError(code_point);
|
|
1455
1576
|
};
|
|
1456
1577
|
}
|
|
@@ -1458,7 +1579,6 @@ function XUserDefinedEncoder(options) {
|
|
|
1458
1579
|
encoders['x-user-defined'] = function (options) {
|
|
1459
1580
|
return new XUserDefinedEncoder(options);
|
|
1460
1581
|
};
|
|
1461
|
-
|
|
1462
1582
|
decoders['x-user-defined'] = function (options) {
|
|
1463
1583
|
return new XUserDefinedDecoder(options);
|
|
1464
1584
|
};
|