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