Add barcode-detector-api-polyfill dependency and update environment variable declarations in SvelteKit project
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class Big5Decoder {
|
||||
readonly fatal: boolean;
|
||||
Big5_lead: number;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
handler(stream: Stream, bite: number): (number | Array<number>) | null;
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var Big5Decoder = /** @class */ (function () {
|
||||
function Big5Decoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
// Big5's decoder has an associated Big5 lead (initially 0x00).
|
||||
/** @type {number} */ this.Big5_lead = 0x00;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
Big5Decoder.prototype.handler = function (stream, bite) {
|
||||
// 1. If byte is end-of-stream and Big5 lead is not 0x00, set
|
||||
// Big5 lead to 0x00 and return error.
|
||||
if (bite === terminology_1.end_of_stream && this.Big5_lead !== 0x00) {
|
||||
this.Big5_lead = 0x00;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 2. If byte is end-of-stream and Big5 lead is 0x00, return
|
||||
// finished.
|
||||
if (bite === terminology_1.end_of_stream && this.Big5_lead === 0x00)
|
||||
return finished_1.finished;
|
||||
// 3. If Big5 lead is not 0x00, let lead be Big5 lead, let
|
||||
// pointer be null, set Big5 lead to 0x00, and then run these
|
||||
// substeps:
|
||||
if (this.Big5_lead !== 0x00) {
|
||||
var lead = this.Big5_lead;
|
||||
var pointer = null;
|
||||
this.Big5_lead = 0x00;
|
||||
// 1. Let offset be 0x40 if byte is less than 0x7F and 0x62
|
||||
// otherwise.
|
||||
var offset = bite < 0x7F ? 0x40 : 0x62;
|
||||
// 2. If byte is in the range 0x40 to 0x7E, inclusive, or 0xA1
|
||||
// to 0xFE, inclusive, set pointer to (lead − 0x81) × 157 +
|
||||
// (byte − offset).
|
||||
if (utilities_1.inRange(bite, 0x40, 0x7E) || utilities_1.inRange(bite, 0xA1, 0xFE))
|
||||
pointer = (lead - 0x81) * 157 + (bite - offset);
|
||||
// 3. If there is a row in the table below whose first column
|
||||
// is pointer, return the two code points listed in its second
|
||||
// column
|
||||
// Pointer | Code points
|
||||
// --------+--------------
|
||||
// 1133 | U+00CA U+0304
|
||||
// 1135 | U+00CA U+030C
|
||||
// 1164 | U+00EA U+0304
|
||||
// 1166 | U+00EA U+030C
|
||||
switch (pointer) {
|
||||
case 1133: return [0x00CA, 0x0304];
|
||||
case 1135: return [0x00CA, 0x030C];
|
||||
case 1164: return [0x00EA, 0x0304];
|
||||
case 1166: return [0x00EA, 0x030C];
|
||||
}
|
||||
// 4. Let code point be null if pointer is null and the index
|
||||
// code point for pointer in index Big5 otherwise.
|
||||
var code_point = (pointer === null) ? null :
|
||||
indexes_1.indexCodePointFor(pointer, indexes_1.index('big5'));
|
||||
// 5. If code point is null and byte is an ASCII byte, prepend
|
||||
// byte to stream.
|
||||
if (code_point === null && terminology_1.isASCIIByte(bite))
|
||||
stream.prepend(bite);
|
||||
// 6. If code point is null, return error.
|
||||
if (code_point === null)
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
// 7. Return a code point whose value is code point.
|
||||
return code_point;
|
||||
}
|
||||
// 4. If byte is an ASCII byte, return a code point whose value
|
||||
// is byte.
|
||||
if (terminology_1.isASCIIByte(bite))
|
||||
return bite;
|
||||
// 5. If byte is in the range 0x81 to 0xFE, inclusive, set Big5
|
||||
// lead to byte and return continue.
|
||||
if (utilities_1.inRange(bite, 0x81, 0xFE)) {
|
||||
this.Big5_lead = bite;
|
||||
return null;
|
||||
}
|
||||
// 6. Return error.
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
};
|
||||
return Big5Decoder;
|
||||
}());
|
||||
exports.Big5Decoder = Big5Decoder;
|
||||
//# sourceMappingURL=Big5Decoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Big5Decoder.js","sourceRoot":"","sources":["../../../../src/coders/big5/Big5Decoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAAkE;AAClE,0DAAwE;AACxE,sDAAmD;AAEnD;;;;IAII;AACJ;IAME,qBAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,+DAA+D;QAC/D,qBAAqB,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC9C,CAAC;IAED;;;;;;OAMG;IACH,6BAAO,GAAP,UAAQ,MAAc,EAAE,IAAY;QAClC,6DAA6D;QAC7D,sCAAsC;QACtC,IAAI,IAAI,KAAK,2BAAa,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE;YACrD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;QAED,4DAA4D;QAC5D,Y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O,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC5C,2BAAiB,CAAC,OAAO,EAAE,eAAK,CAAC,MAAM,CAAa,CAAC,CAAC;YAExD,8DAA8D;YAC9D,kBAAkB;YAClB,IAAI,UAAU,KAAK,IAAI,IAAI,yBAAW,CAAC,IAAI,CAAC;gBAC1C,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAEvB,0CAA0C;YAC1C,IAAI,UAAU,KAAK,IAAI;gBACrB,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAElC,oDAAoD;YACpD,OAAO,UAAU,CAAC;SACnB;QAED,+DAA+D;QAC/D,WAAW;QACX,IAAI,yBAAW,CAAC,IAAI,CAAC;YACnB,OAAO,IAAI,CAAC;QAEd,+DAA+D;QAC/D,oCAAoC;QACpC,IAAI,mBAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YAC7B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,OAAO,IAAI,CAAC;SACb;QAED,mBAAmB;QACnB,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IACH,kBAAC;AAAD,CAAC,AAnGD,IAmGC;AAnGY,kCAAW"}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class Big5Encoder {
|
||||
readonly fatal: boolean;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
handler(stream: Stream, code_point: number): (number | Array<number>);
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var Big5Encoder = /** @class */ (function () {
|
||||
function Big5Encoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
Big5Encoder.prototype.handler = function (stream, code_point) {
|
||||
// 1. If code point is end-of-stream, return finished.
|
||||
if (code_point === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 2. If code point is an ASCII code point, return a byte whose
|
||||
// value is code point.
|
||||
if (terminology_1.isASCIICodePoint(code_point))
|
||||
return code_point;
|
||||
// 3. Let pointer be the index Big5 pointer for code point.
|
||||
var pointer = indexes_1.indexBig5PointerFor(code_point);
|
||||
// 4. If pointer is null, return error with code point.
|
||||
if (pointer === null)
|
||||
return encodings_1.encoderError(code_point);
|
||||
// 5. Let lead be Math.floor(pointer / 157) + 0x81.
|
||||
var lead = Math.floor(pointer / 157) + 0x81;
|
||||
// 6. If lead is less than 0xA1, return error with code point.
|
||||
if (lead < 0xA1)
|
||||
return encodings_1.encoderError(code_point);
|
||||
// 7. Let trail be pointer % 157.
|
||||
var trail = pointer % 157;
|
||||
// 8. Let offset be 0x40 if trail is less than 0x3F and 0x62
|
||||
// otherwise.
|
||||
var offset = trail < 0x3F ? 0x40 : 0x62;
|
||||
// Return two bytes whose values are lead and trail + offset.
|
||||
return [lead, trail + offset];
|
||||
};
|
||||
return Big5Encoder;
|
||||
}());
|
||||
exports.Big5Encoder = Big5Encoder;
|
||||
//# sourceMappingURL=Big5Encoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Big5Encoder.js","sourceRoot":"","sources":["../../../../src/coders/big5/Big5Encoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAA6D;AAC7D,0DAA6E;AAE7E;;;;KAIK;AACL;IAIE,qBAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,6BAAO,GAAP,UAAQ,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,2BAAa;YAC9B,OAAO,mBAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,8BAAgB,CAAC,UAAU,CAAC;YAC9B,OAAO,UAAU,CAAC;QAEpB,2DAA2D;QAC3D,IAAM,OAAO,GAAG,6BAAmB,CAAC,UAAU,CAAC,CAAC;QAEhD,uDAAuD;QACvD,IAAI,OAAO,KAAK,IAAI;YAClB,OAAO,wBAAY,CAAC,UAAU,CAAC,CAAC;QAElC,mDAAmD;QACnD,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;QAE9C,8DAA8D;QAC9D,IAAI,IAAI,GAAG,IAAI;YACb,OAAO,wBAAY,CAAC,UAAU,CAAC,CAAC;QAElC,iCAAiC;QACjC,IAAM,KAAK,GAAG,OAAO,GAAG,GAAG,CAAC;QAE5B,4DAA4D;QAC5D,aAAa;QACb,IAAM,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAE1C,6DAA6D;QAC7D,OAAO,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;IAChC,CAAC;IACH,kBAAC;AAAD,CAAC,AA/CD,IA+CC;AA/CY,kCAAW"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './Big5Decoder';
|
||||
export * from './Big5Encoder';
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./Big5Decoder"));
|
||||
__export(require("./Big5Encoder"));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/big5/index.ts"],"names":[],"mappings":";;;;;AAAA,mCAA8B;AAC9B,mCAA8B"}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { Stream } from "../../common";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class EUCJPDecoder {
|
||||
readonly fatal: boolean;
|
||||
eucjp_jis0212_flag: boolean;
|
||||
eucjp_lead: number;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
handler(stream: Stream, bite: number): (number | Array<number>) | null;
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var EUCJPDecoder = /** @class */ (function () {
|
||||
function EUCJPDecoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
// euc-jp's decoder has an associated euc-jp jis0212 flag
|
||||
// (initially unset) and euc-jp lead (initially 0x00).
|
||||
/** @type {boolean} */ this.eucjp_jis0212_flag = false,
|
||||
/** @type {number} */ this.eucjp_lead = 0x00;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
EUCJPDecoder.prototype.handler = function (stream, bite) {
|
||||
// 1. If byte is end-of-stream and euc-jp lead is not 0x00, set
|
||||
// euc-jp lead to 0x00, and return error.
|
||||
if (bite === terminology_1.end_of_stream && this.eucjp_lead !== 0x00) {
|
||||
this.eucjp_lead = 0x00;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 2. If byte is end-of-stream and euc-jp lead is 0x00, return
|
||||
// finished.
|
||||
if (bite === terminology_1.end_of_stream && this.eucjp_lead === 0x00)
|
||||
return finished_1.finished;
|
||||
// 3. If euc-jp lead is 0x8E and byte is in the range 0xA1 to
|
||||
// 0xDF, inclusive, set euc-jp lead to 0x00 and return a code
|
||||
// point whose value is 0xFF61 − 0xA1 + byte.
|
||||
if (this.eucjp_lead === 0x8E && utilities_1.inRange(bite, 0xA1, 0xDF)) {
|
||||
this.eucjp_lead = 0x00;
|
||||
return 0xFF61 - 0xA1 + bite;
|
||||
}
|
||||
// 4. If euc-jp lead is 0x8F and byte is in the range 0xA1 to
|
||||
// 0xFE, inclusive, set the euc-jp jis0212 flag, set euc-jp lead
|
||||
// to byte, and return continue.
|
||||
if (this.eucjp_lead === 0x8F && utilities_1.inRange(bite, 0xA1, 0xFE)) {
|
||||
this.eucjp_jis0212_flag = true;
|
||||
this.eucjp_lead = bite;
|
||||
return null;
|
||||
}
|
||||
// 5. If euc-jp lead is not 0x00, let lead be euc-jp lead, set
|
||||
// euc-jp lead to 0x00, and run these substeps:
|
||||
if (this.eucjp_lead !== 0x00) {
|
||||
var lead = this.eucjp_lead;
|
||||
this.eucjp_lead = 0x00;
|
||||
// 1. Let code point be null.
|
||||
var code_point = null;
|
||||
// 2. If lead and byte are both in the range 0xA1 to 0xFE,
|
||||
// inclusive, set code point to the index code point for (lead
|
||||
// − 0xA1) × 94 + byte − 0xA1 in index jis0208 if the euc-jp
|
||||
// jis0212 flag is unset and in index jis0212 otherwise.
|
||||
if (utilities_1.inRange(lead, 0xA1, 0xFE) && utilities_1.inRange(bite, 0xA1, 0xFE)) {
|
||||
code_point = indexes_1.indexCodePointFor((lead - 0xA1) * 94 + (bite - 0xA1), indexes_1.index(!this.eucjp_jis0212_flag ? 'jis0208' : 'jis0212'));
|
||||
}
|
||||
// 3. Unset the euc-jp jis0212 flag.
|
||||
this.eucjp_jis0212_flag = false;
|
||||
// 4. If byte is not in the range 0xA1 to 0xFE, inclusive,
|
||||
// prepend byte to stream.
|
||||
if (!utilities_1.inRange(bite, 0xA1, 0xFE))
|
||||
stream.prepend(bite);
|
||||
// 5. If code point is null, return error.
|
||||
if (code_point === null)
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
// 6. Return a code point whose value is code point.
|
||||
return code_point;
|
||||
}
|
||||
// 6. If byte is an ASCII byte, return a code point whose value
|
||||
// is byte.
|
||||
if (terminology_1.isASCIIByte(bite))
|
||||
return bite;
|
||||
// 7. If byte is 0x8E, 0x8F, or in the range 0xA1 to 0xFE,
|
||||
// inclusive, set euc-jp lead to byte and return continue.
|
||||
if (bite === 0x8E || bite === 0x8F || utilities_1.inRange(bite, 0xA1, 0xFE)) {
|
||||
this.eucjp_lead = bite;
|
||||
return null;
|
||||
}
|
||||
// 8. Return error.
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
};
|
||||
return EUCJPDecoder;
|
||||
}());
|
||||
exports.EUCJPDecoder = EUCJPDecoder;
|
||||
//# sourceMappingURL=EUCJPDecoder.js.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,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,mBAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YAC/D,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,OAAO,IAAI,CAAC;SACb;QAED,mBAAmB;QACnB,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IACH,mBAAC;AAAD,CAAC,AAvGD,IAuGC;AAvGY,oCAAY"}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { Stream } from "../../common";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class EUCJPEncoder {
|
||||
readonly fatal: boolean;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
handler(stream: Stream, code_point: number): (number | Array<number>);
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var EUCJPEncoder = /** @class */ (function () {
|
||||
function EUCJPEncoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
EUCJPEncoder.prototype.handler = function (stream, code_point) {
|
||||
// 1. If code point is end-of-stream, return finished.
|
||||
if (code_point === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 2. If code point is an ASCII code point, return a byte whose
|
||||
// value is code point.
|
||||
if (terminology_1.isASCIICodePoint(code_point))
|
||||
return code_point;
|
||||
// 3. If code point is U+00A5, return byte 0x5C.
|
||||
if (code_point === 0x00A5)
|
||||
return 0x5C;
|
||||
// 4. If code point is U+203E, return byte 0x7E.
|
||||
if (code_point === 0x203E)
|
||||
return 0x7E;
|
||||
// 5. If code point is in the range U+FF61 to U+FF9F, inclusive,
|
||||
// return two bytes whose values are 0x8E and code point −
|
||||
// 0xFF61 + 0xA1.
|
||||
if (utilities_1.inRange(code_point, 0xFF61, 0xFF9F))
|
||||
return [0x8E, code_point - 0xFF61 + 0xA1];
|
||||
// 6. If code point is U+2212, set it to U+FF0D.
|
||||
if (code_point === 0x2212)
|
||||
code_point = 0xFF0D;
|
||||
// 7. Let pointer be the index pointer for code point in index
|
||||
// jis0208.
|
||||
var pointer = indexes_1.indexPointerFor(code_point, indexes_1.index('jis0208'));
|
||||
// 8. If pointer is null, return error with code point.
|
||||
if (pointer === null)
|
||||
return encodings_1.encoderError(code_point);
|
||||
// 9. Let lead be Math.floor(pointer / 94) + 0xA1.
|
||||
var lead = Math.floor(pointer / 94) + 0xA1;
|
||||
// 10. Let trail be pointer % 94 + 0xA1.
|
||||
var trail = pointer % 94 + 0xA1;
|
||||
// 11. Return two bytes whose values are lead and trail.
|
||||
return [lead, trail];
|
||||
};
|
||||
return EUCJPEncoder;
|
||||
}());
|
||||
exports.EUCJPEncoder = EUCJPEncoder;
|
||||
//# sourceMappingURL=EUCJPEncoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"EUCJPEncoder.js","sourceRoot":"","sources":["../../../../src/coders/euc-jp/EUCJPEncoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAAgE;AAChE,0DAA6E;A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A0DC;AA1DY,oCAAY"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './EUCJPDecoder';
|
||||
export * from './EUCJPEncoder';
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./EUCJPDecoder"));
|
||||
__export(require("./EUCJPEncoder"));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/euc-jp/index.ts"],"names":[],"mappings":";;;;;AAAA,oCAA+B;AAC/B,oCAA+B"}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { Stream } from "../../common";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class EUCKRDecoder {
|
||||
readonly fatal: boolean;
|
||||
euckr_lead: number;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
handler(stream: Stream, bite: number): (number | Array<number>) | null;
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var EUCKRDecoder = /** @class */ (function () {
|
||||
function EUCKRDecoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
// euc-kr's decoder has an associated euc-kr lead (initially 0x00).
|
||||
/** @type {number} */ this.euckr_lead = 0x00;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
EUCKRDecoder.prototype.handler = function (stream, bite) {
|
||||
// 1. If byte is end-of-stream and euc-kr lead is not 0x00, set
|
||||
// euc-kr lead to 0x00 and return error.
|
||||
if (bite === terminology_1.end_of_stream && this.euckr_lead !== 0) {
|
||||
this.euckr_lead = 0x00;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 2. If byte is end-of-stream and euc-kr lead is 0x00, return
|
||||
// finished.
|
||||
if (bite === terminology_1.end_of_stream && this.euckr_lead === 0)
|
||||
return finished_1.finished;
|
||||
// 3. If euc-kr lead is not 0x00, let lead be euc-kr lead, let
|
||||
// pointer be null, set euc-kr lead to 0x00, and then run these
|
||||
// substeps:
|
||||
if (this.euckr_lead !== 0x00) {
|
||||
var lead = this.euckr_lead;
|
||||
var pointer = null;
|
||||
this.euckr_lead = 0x00;
|
||||
// 1. If byte is in the range 0x41 to 0xFE, inclusive, set
|
||||
// pointer to (lead − 0x81) × 190 + (byte − 0x41).
|
||||
if (utilities_1.inRange(bite, 0x41, 0xFE))
|
||||
pointer = (lead - 0x81) * 190 + (bite - 0x41);
|
||||
// 2. Let code point be null, if pointer is null, and the
|
||||
// index code point for pointer in index euc-kr otherwise.
|
||||
var code_point = (pointer === null)
|
||||
? null : indexes_1.indexCodePointFor(pointer, indexes_1.index('euc-kr'));
|
||||
// 3. If code point is null and byte is an ASCII byte, prepend
|
||||
// byte to stream.
|
||||
if (pointer === null && terminology_1.isASCIIByte(bite))
|
||||
stream.prepend(bite);
|
||||
// 4. If code point is null, return error.
|
||||
if (code_point === null)
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
// 5. Return a code point whose value is code point.
|
||||
return code_point;
|
||||
}
|
||||
// 4. If byte is an ASCII byte, return a code point whose value
|
||||
// is byte.
|
||||
if (terminology_1.isASCIIByte(bite))
|
||||
return bite;
|
||||
// 5. If byte is in the range 0x81 to 0xFE, inclusive, set
|
||||
// euc-kr lead to byte and return continue.
|
||||
if (utilities_1.inRange(bite, 0x81, 0xFE)) {
|
||||
this.euckr_lead = bite;
|
||||
return null;
|
||||
}
|
||||
// 6. Return error.
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
};
|
||||
return EUCKRDecoder;
|
||||
}());
|
||||
exports.EUCKRDecoder = EUCKRDecoder;
|
||||
//# sourceMappingURL=EUCKRDecoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"EUCKRDecoder.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/EUCKRDecoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAAkE;AAClE,0DAAwE;AACxE,sDAAmD;AAEnD;;;;GAIG;AACH;IAME,sBAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE3B,mEAAmE;QACnE,qBAAqB,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IAC/C,CAAC;IACD;;;;;;OAMG;IACH,8BAAO,GAAP,UAAQ,MAAc,EAAE,IAAY;QAClC,+DAA+D;QAC/D,wCAAwC;QACxC,IAAI,IAAI,KAAK,2BAAa,IAAI,IAAI,CAAC,UAAU,KAAK,CAAC,EAAE;YACnD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;QAED,8DAA8D;QAC9D,YAAY;QACZ,IAAI,IAAI,KAAK,2BAAa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B;QACnB,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IACH,mBAAC;AAAD,CAAC,AA9ED,IA8EC;AA9EY,oCAAY"}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { Stream } from "../../common";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class EUCKREncoder {
|
||||
readonly fatal: boolean;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
handler(stream: Stream, code_point: number): (number | Array<number>);
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var EUCKREncoder = /** @class */ (function () {
|
||||
function EUCKREncoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
EUCKREncoder.prototype.handler = function (stream, code_point) {
|
||||
// 1. If code point is end-of-stream, return finished.
|
||||
if (code_point === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 2. If code point is an ASCII code point, return a byte whose
|
||||
// value is code point.
|
||||
if (terminology_1.isASCIICodePoint(code_point))
|
||||
return code_point;
|
||||
// 3. Let pointer be the index pointer for code point in index
|
||||
// euc-kr.
|
||||
var pointer = indexes_1.indexPointerFor(code_point, indexes_1.index('euc-kr'));
|
||||
// 4. If pointer is null, return error with code point.
|
||||
if (pointer === null)
|
||||
return encodings_1.encoderError(code_point);
|
||||
// 5. Let lead be Math.floor(pointer / 190) + 0x81.
|
||||
var lead = Math.floor(pointer / 190) + 0x81;
|
||||
// 6. Let trail be pointer % 190 + 0x41.
|
||||
var trail = (pointer % 190) + 0x41;
|
||||
// 7. Return two bytes whose values are lead and trail.
|
||||
return [lead, trail];
|
||||
};
|
||||
return EUCKREncoder;
|
||||
}());
|
||||
exports.EUCKREncoder = EUCKREncoder;
|
||||
//# sourceMappingURL=EUCKREncoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"EUCKREncoder.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/EUCKREncoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAAgE;AAChE,0DAA6E;AAE7E;;;;GAIG;AACH;IAIE,sBAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,8BAAO,GAAP,UAAQ,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,2BAAa;YAC9B,OAAO,mBAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,8BAAgB,CAAC,UAAU,CAAC;YAC9B,OAAO,UAAU,CAAC;QAEpB,8DAA8D;QAC9D,UAAU;QACV,IAAM,OAAO,GAAG,yBAAe,CAAC,UAAU,EAAE,eAAK,CAAC,QAAQ,CAAa,CAAC,CAAC;QAEzE,uDAAuD;QACvD,IAAI,OAAO,KAAK,IAAI;YAClB,OAAO,wBAAY,CAAC,UAAU,CAAC,CAAC;QAElC,mDAAmD;QACnD,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;QAE9C,wCAAwC;QACxC,IAAM,KAAK,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;QAErC,uDAAuD;QACvD,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IACH,mBAAC;AAAD,CAAC,AAxCD,IAwCC;AAxCY,oCAAY"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './EUCKRDecoder';
|
||||
export * from './EUCKREncoder';
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./EUCKRDecoder"));
|
||||
__export(require("./EUCKREncoder"));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/index.ts"],"names":[],"mappings":";;;;;AAAA,oCAA+B;AAC/B,oCAA+B"}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class GB18030Decoder {
|
||||
readonly fatal: boolean;
|
||||
gb18030_first: number;
|
||||
gb18030_second: number;
|
||||
gb18030_third: number;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
handler(stream: Stream, bite: number): (number | Array<number>) | null;
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var GB18030Decoder = /** @class */ (function () {
|
||||
function GB18030Decoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
// gb18030's decoder has an associated gb18030 first, gb18030
|
||||
// second, and gb18030 third (all initially 0x00).
|
||||
/** @type {number} */ this.gb18030_first = 0x00,
|
||||
/** @type {number} */ this.gb18030_second = 0x00,
|
||||
/** @type {number} */ this.gb18030_third = 0x00;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
GB18030Decoder.prototype.handler = function (stream, bite) {
|
||||
// 1. If byte is end-of-stream and gb18030 first, gb18030
|
||||
// second, and gb18030 third are 0x00, return finished.
|
||||
if (bite === terminology_1.end_of_stream && this.gb18030_first === 0x00 &&
|
||||
this.gb18030_second === 0x00 && this.gb18030_third === 0x00) {
|
||||
return finished_1.finished;
|
||||
}
|
||||
// 2. If byte is end-of-stream, and gb18030 first, gb18030
|
||||
// second, or gb18030 third is not 0x00, set gb18030 first,
|
||||
// gb18030 second, and gb18030 third to 0x00, and return error.
|
||||
if (bite === terminology_1.end_of_stream &&
|
||||
(this.gb18030_first !== 0x00 || this.gb18030_second !== 0x00 ||
|
||||
this.gb18030_third !== 0x00)) {
|
||||
this.gb18030_first = 0x00;
|
||||
this.gb18030_second = 0x00;
|
||||
this.gb18030_third = 0x00;
|
||||
encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
var code_point;
|
||||
// 3. If gb18030 third is not 0x00, run these substeps:
|
||||
if (this.gb18030_third !== 0x00) {
|
||||
// 1. Let code point be null.
|
||||
code_point = null;
|
||||
// 2. If byte is in the range 0x30 to 0x39, inclusive, set
|
||||
// code point to the index gb18030 ranges code point for
|
||||
// (((gb18030 first − 0x81) × 10 + gb18030 second − 0x30) ×
|
||||
// 126 + gb18030 third − 0x81) × 10 + byte − 0x30.
|
||||
if (utilities_1.inRange(bite, 0x30, 0x39)) {
|
||||
code_point = indexes_1.indexGB18030RangesCodePointFor((((this.gb18030_first - 0x81) * 10 + this.gb18030_second - 0x30) * 126 +
|
||||
this.gb18030_third - 0x81) * 10 + bite - 0x30);
|
||||
}
|
||||
// 3. Let buffer be a byte sequence consisting of gb18030
|
||||
// second, gb18030 third, and byte, in order.
|
||||
var buffer = [this.gb18030_second, this.gb18030_third, bite];
|
||||
// 4. Set gb18030 first, gb18030 second, and gb18030 third to
|
||||
// 0x00.
|
||||
this.gb18030_first = 0x00;
|
||||
this.gb18030_second = 0x00;
|
||||
this.gb18030_third = 0x00;
|
||||
// 5. If code point is null, prepend buffer to stream and
|
||||
// return error.
|
||||
if (code_point === null) {
|
||||
stream.prepend(buffer);
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 6. Return a code point whose value is code point.
|
||||
return code_point;
|
||||
}
|
||||
// 4. If gb18030 second is not 0x00, run these substeps:
|
||||
if (this.gb18030_second !== 0x00) {
|
||||
// 1. If byte is in the range 0x81 to 0xFE, inclusive, set
|
||||
// gb18030 third to byte and return continue.
|
||||
if (utilities_1.inRange(bite, 0x81, 0xFE)) {
|
||||
this.gb18030_third = bite;
|
||||
return null;
|
||||
}
|
||||
// 2. Prepend gb18030 second followed by byte to stream, set
|
||||
// gb18030 first and gb18030 second to 0x00, and return error.
|
||||
stream.prepend([this.gb18030_second, bite]);
|
||||
this.gb18030_first = 0x00;
|
||||
this.gb18030_second = 0x00;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 5. If gb18030 first is not 0x00, run these substeps:
|
||||
if (this.gb18030_first !== 0x00) {
|
||||
// 1. If byte is in the range 0x30 to 0x39, inclusive, set
|
||||
// gb18030 second to byte and return continue.
|
||||
if (utilities_1.inRange(bite, 0x30, 0x39)) {
|
||||
this.gb18030_second = bite;
|
||||
return null;
|
||||
}
|
||||
// 2. Let lead be gb18030 first, let pointer be null, and set
|
||||
// gb18030 first to 0x00.
|
||||
var lead = this.gb18030_first;
|
||||
var pointer = null;
|
||||
this.gb18030_first = 0x00;
|
||||
// 3. Let offset be 0x40 if byte is less than 0x7F and 0x41
|
||||
// otherwise.
|
||||
var offset = bite < 0x7F ? 0x40 : 0x41;
|
||||
// 4. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80
|
||||
// to 0xFE, inclusive, set pointer to (lead − 0x81) × 190 +
|
||||
// (byte − offset).
|
||||
if (utilities_1.inRange(bite, 0x40, 0x7E) || utilities_1.inRange(bite, 0x80, 0xFE))
|
||||
pointer = (lead - 0x81) * 190 + (bite - offset);
|
||||
// 5. Let code point be null if pointer is null and the index
|
||||
// code point for pointer in index gb18030 otherwise.
|
||||
code_point = pointer === null ? null :
|
||||
indexes_1.indexCodePointFor(pointer, indexes_1.index('gb18030'));
|
||||
// 6. If code point is null and byte is an ASCII byte, prepend
|
||||
// byte to stream.
|
||||
if (code_point === null && terminology_1.isASCIIByte(bite))
|
||||
stream.prepend(bite);
|
||||
// 7. If code point is null, return error.
|
||||
if (code_point === null)
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
// 8. Return a code point whose value is code point.
|
||||
return code_point;
|
||||
}
|
||||
// 6. If byte is an ASCII byte, return a code point whose value
|
||||
// is byte.
|
||||
if (terminology_1.isASCIIByte(bite))
|
||||
return bite;
|
||||
// 7. If byte is 0x80, return code point U+20AC.
|
||||
if (bite === 0x80)
|
||||
return 0x20AC;
|
||||
// 8. If byte is in the range 0x81 to 0xFE, inclusive, set
|
||||
// gb18030 first to byte and return continue.
|
||||
if (utilities_1.inRange(bite, 0x81, 0xFE)) {
|
||||
this.gb18030_first = bite;
|
||||
return null;
|
||||
}
|
||||
// 9. Return error.
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
};
|
||||
return GB18030Decoder;
|
||||
}());
|
||||
exports.GB18030Decoder = GB18030Decoder;
|
||||
//# sourceMappingURL=GB18030Decoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GB18030Decoder.js","sourceRoot":"","sources":["../../../../src/coders/gb18030/GB18030Decoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAAkG;AAClG,0DAAwE;AACxE,sDAAmD;AAEnD;;;;GAIG;AACH;IAQE,wBAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,6DAA6D;QAC7D,kDAAkD;QAClD,qBAAqB,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI;YAC/C,qBAAqB,CAAC,IAAI,CAAC,cAAc,GAAG,IAAI;YAChD,qBAAqB,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAClD,CAAC;IAED;;;;;;OAMG;IACH,gCAAO,GAAP,UAAQ,MAAc,EAAE,IAAY;QAClC,yDAAyD;QACzD,uDAAuD;QACvD,IAAI,IAAI,KAAK,2BAAa,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI;YACvD,IAAI,CAAC,cAAc,KAAK,IAAI,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,EAAE;YAC7D,OAAO,mBAAQ,CAAC;SACjB;QACD,0DAA0D;QAC1D,2DAA2D;QAC3D,+DAA+D;QAC/D,IAAI,IAAI,KAAK,2BAAa;YACxB,CAAC,IAAI,CAAC,aAAa,KAAK,IAAI,IAAI,IAAI,CAAC,cAAc,KAAK,IAAI;gBAC1D,IAAI,CAAC,aAAa,KAAK,IAAI,CAAC,EAAE;YAChC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAC1B,IAA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YACrD,UAAU,GAAG,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBACpC,2BAAiB,CAAC,OAAO,EAAE,eAAK,CAAC,SAAS,CAAa,CAAC,CAAC;YAC3D,8DAA8D;YAC9D,kBAAkB;YAClB,IAAI,UAAU,KAAK,IAAI,IAAI,yBAAW,CAAC,IAAI,CAAC;gBAC1C,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACvB,0CAA0C;YAC1C,IAAI,UAAU,KAAK,IAAI;gBACrB,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClC,oDAAoD;YACpD,OAAO,UAAU,CAAC;SACnB;QACD,+DAA+D;QAC/D,WAAW;QACX,IAAI,yBAAW,CAAC,IAAI,CAAC;YACnB,OAAO,IAAI,CAAC;QACd,gDAAgD;QAChD,IAAI,IAAI,KAAK,IAAI;YACf,OAAO,MAAM,CAAC;QAChB,0DAA0D;QAC1D,6CAA6C;QAC7C,IAAI,mBAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YAC7B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAC1B,OAAO,IAAI,CAAC;SACb;QACD,mBAAmB;QACnB,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IACH,qBAAC;AAAD,CAAC,AA1ID,IA0IC;AA1IY,wCAAc"}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
* @param {boolean=} gbk_flag
|
||||
*/
|
||||
export declare class GB18030Encoder {
|
||||
private gbk_flag;
|
||||
readonly fatal: boolean;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
}, gbk_flag?: boolean);
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
handler(stream: Stream, code_point: number): (number | Array<number>);
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
* @param {boolean=} gbk_flag
|
||||
*/
|
||||
var GB18030Encoder = /** @class */ (function () {
|
||||
function GB18030Encoder(options, gbk_flag) {
|
||||
if (gbk_flag === void 0) { gbk_flag = undefined; }
|
||||
this.gbk_flag = gbk_flag;
|
||||
this.fatal = options.fatal;
|
||||
// gb18030's decoder has an associated gbk flag (initially unset).
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
GB18030Encoder.prototype.handler = function (stream, code_point) {
|
||||
// 1. If code point is end-of-stream, return finished.
|
||||
if (code_point === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 2. If code point is an ASCII code point, return a byte whose
|
||||
// value is code point.
|
||||
if (terminology_1.isASCIICodePoint(code_point))
|
||||
return code_point;
|
||||
// 3. If code point is U+E5E5, return error with code point.
|
||||
if (code_point === 0xE5E5)
|
||||
return encodings_1.encoderError(code_point);
|
||||
// 4. If the gbk flag is set and code point is U+20AC, return
|
||||
// byte 0x80.
|
||||
if (this.gbk_flag && code_point === 0x20AC)
|
||||
return 0x80;
|
||||
// 5. Let pointer be the index pointer for code point in index
|
||||
// gb18030.
|
||||
var pointer = indexes_1.indexPointerFor(code_point, indexes_1.index('gb18030'));
|
||||
// 6. If pointer is not null, run these substeps:
|
||||
if (pointer !== null) {
|
||||
// 1. Let lead be Math.floor(pointer / 190) + 0x81.
|
||||
var lead = Math.floor(pointer / 190) + 0x81;
|
||||
// 2. Let trail be pointer % 190.
|
||||
var trail = pointer % 190;
|
||||
// 3. Let offset be 0x40 if trail is less than 0x3F and 0x41 otherwise.
|
||||
var offset = trail < 0x3F ? 0x40 : 0x41;
|
||||
// 4. Return two bytes whose values are lead and trail + offset.
|
||||
return [lead, trail + offset];
|
||||
}
|
||||
// 7. If gbk flag is set, return error with code point.
|
||||
if (this.gbk_flag)
|
||||
return encodings_1.encoderError(code_point);
|
||||
// 8. Set pointer to the index gb18030 ranges pointer for code
|
||||
// point.
|
||||
pointer = indexes_1.indexGB18030RangesPointerFor(code_point);
|
||||
// 9. Let byte1 be Math.floor(pointer / 10 / 126 / 10).
|
||||
var byte1 = Math.floor(pointer / 10 / 126 / 10);
|
||||
// 10. Set pointer to pointer − byte1 × 10 × 126 × 10.
|
||||
pointer = pointer - byte1 * 10 * 126 * 10;
|
||||
// 11. Let byte2 be Math.floor(pointer / 10 / 126).
|
||||
var byte2 = Math.floor(pointer / 10 / 126);
|
||||
// 12. Set pointer to pointer − byte2 × 10 × 126.
|
||||
pointer = pointer - byte2 * 10 * 126;
|
||||
// 13. Let byte3 be Math.floor(pointer / 10).
|
||||
var byte3 = Math.floor(pointer / 10);
|
||||
// 14. Let byte4 be pointer − byte3 × 10.
|
||||
var byte4 = pointer - byte3 * 10;
|
||||
// 15. Return four bytes whose values are byte1 + 0x81, byte2 +
|
||||
// 0x30, byte3 + 0x81, byte4 + 0x30.
|
||||
return [byte1 + 0x81,
|
||||
byte2 + 0x30,
|
||||
byte3 + 0x81,
|
||||
byte4 + 0x30];
|
||||
};
|
||||
return GB18030Encoder;
|
||||
}());
|
||||
exports.GB18030Encoder = GB18030Encoder;
|
||||
//# sourceMappingURL=GB18030Encoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GB18030Encoder.js","sourceRoot":"","sources":["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MAAM,CAAC,CAAC;SAC/B;QAED,uDAAuD;QACvD,IAAI,IAAI,CAAC,QAAQ;YACf,OAAO,wBAAY,CAAC,UAAU,CAAC,CAAC;QAElC,8DAA8D;QAC9D,SAAS;QACT,OAAO,GAAG,sCAA4B,CAAC,UAAU,CAAC,CAAC;QAEnD,uDAAuD;QACvD,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC;QAElD,sDAAsD;QACtD,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;QAE1C,mDAAmD;QACnD,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;QAE7C,iDAAiD;QACjD,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,GAAG,CAAC;QAErC,6CAA6C;QAC7C,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC;QAEvC,yCAAyC;QACzC,IAAM,KAAK,GAAG,OAAO,GAAG,KAAK,GAAG,EAAE,CAAC;QAEnC,+DAA+D;QAC/D,oCAAoC;QACpC,OAAO,CAAC,KAAK,GAAG,IAAI;YACpB,KAAK,GAAG,IAAI;YACZ,KAAK,GAAG,IAAI;YACZ,KAAK,GAAG,IAAI,CAAC,CAAC;IAChB,CAAC;IACH,qBAAC;AAAD,CAAC,AAtFD,IAsFC;AAtFY,wCAAc"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './GB18030Decoder';
|
||||
export * from './GB18030Encoder';
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./GB18030Decoder"));
|
||||
__export(require("./GB18030Encoder"));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/gb18030/index.ts"],"names":[],"mappings":";;;;;AAAA,sCAAiC;AACjC,sCAAiC"}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
export declare class ISO2022JPDecoder {
|
||||
readonly fatal: boolean;
|
||||
iso2022jp_decoder_state: any;
|
||||
iso2022jp_decoder_output_state: any;
|
||||
iso2022jp_lead: number;
|
||||
iso2022jp_output_flag: boolean;
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
handler(stream: Stream, bite: number): (number | Array<number>) | null;
|
||||
}
|
||||
+272
@@ -0,0 +1,272 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
var states;
|
||||
(function (states) {
|
||||
states[states["ASCII"] = 0] = "ASCII";
|
||||
states[states["Roman"] = 1] = "Roman";
|
||||
states[states["Katakana"] = 2] = "Katakana";
|
||||
states[states["LeadByte"] = 3] = "LeadByte";
|
||||
states[states["TrailByte"] = 4] = "TrailByte";
|
||||
states[states["EscapeStart"] = 5] = "EscapeStart";
|
||||
states[states["Escape"] = 6] = "Escape";
|
||||
})(states || (states = {}));
|
||||
var ISO2022JPDecoder = /** @class */ (function () {
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
function ISO2022JPDecoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
// iso-2022-jp's decoder has an associated iso-2022-jp decoder
|
||||
// state (initially ASCII), iso-2022-jp decoder output state
|
||||
// (initially ASCII), iso-2022-jp lead (initially 0x00), and
|
||||
// iso-2022-jp output flag (initially unset).
|
||||
/** @type {number} */ this.iso2022jp_decoder_state = states.ASCII,
|
||||
/** @type {number} */ this.iso2022jp_decoder_output_state = states.ASCII,
|
||||
/** @type {number} */ this.iso2022jp_lead = 0x00,
|
||||
/** @type {boolean} */ this.iso2022jp_output_flag = false;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
ISO2022JPDecoder.prototype.handler = function (stream, bite) {
|
||||
// switching on iso-2022-jp decoder state:
|
||||
switch (this.iso2022jp_decoder_state) {
|
||||
default:
|
||||
case states.ASCII:
|
||||
// ASCII
|
||||
// Based on byte:
|
||||
// 0x1B
|
||||
if (bite === 0x1B) {
|
||||
// Set iso-2022-jp decoder state to escape start and return
|
||||
// continue.
|
||||
this.iso2022jp_decoder_state = states.EscapeStart;
|
||||
return null;
|
||||
}
|
||||
// 0x00 to 0x7F, excluding 0x0E, 0x0F, and 0x1B
|
||||
if (utilities_1.inRange(bite, 0x00, 0x7F) && bite !== 0x0E
|
||||
&& bite !== 0x0F && bite !== 0x1B) {
|
||||
// Unset the iso-2022-jp output flag and return a code point
|
||||
// whose value is byte.
|
||||
this.iso2022jp_output_flag = false;
|
||||
return bite;
|
||||
}
|
||||
// end-of-stream
|
||||
if (bite === terminology_1.end_of_stream) {
|
||||
// Return finished.
|
||||
return finished_1.finished;
|
||||
}
|
||||
// Otherwise
|
||||
// Unset the iso-2022-jp output flag and return error.
|
||||
this.iso2022jp_output_flag = false;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
case states.Roman:
|
||||
// Roman
|
||||
// Based on byte:
|
||||
// 0x1B
|
||||
if (bite === 0x1B) {
|
||||
// Set iso-2022-jp decoder state to escape start and return
|
||||
// continue.
|
||||
this.iso2022jp_decoder_state = states.EscapeStart;
|
||||
return null;
|
||||
}
|
||||
// 0x5C
|
||||
if (bite === 0x5C) {
|
||||
// Unset the iso-2022-jp output flag and return code point
|
||||
// U+00A5.
|
||||
this.iso2022jp_output_flag = false;
|
||||
return 0x00A5;
|
||||
}
|
||||
// 0x7E
|
||||
if (bite === 0x7E) {
|
||||
// Unset the iso-2022-jp output flag and return code point
|
||||
// U+203E.
|
||||
this.iso2022jp_output_flag = false;
|
||||
return 0x203E;
|
||||
}
|
||||
// 0x00 to 0x7F, excluding 0x0E, 0x0F, 0x1B, 0x5C, and 0x7E
|
||||
if (utilities_1.inRange(bite, 0x00, 0x7F) && bite !== 0x0E && bite !== 0x0F
|
||||
&& bite !== 0x1B && bite !== 0x5C && bite !== 0x7E) {
|
||||
// Unset the iso-2022-jp output flag and return a code point
|
||||
// whose value is byte.
|
||||
this.iso2022jp_output_flag = false;
|
||||
return bite;
|
||||
}
|
||||
// end-of-stream
|
||||
if (bite === terminology_1.end_of_stream) {
|
||||
// Return finished.
|
||||
return finished_1.finished;
|
||||
}
|
||||
// Otherwise
|
||||
// Unset the iso-2022-jp output flag and return error.
|
||||
this.iso2022jp_output_flag = false;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
case states.Katakana:
|
||||
// Katakana
|
||||
// Based on byte:
|
||||
// 0x1B
|
||||
if (bite === 0x1B) {
|
||||
// Set iso-2022-jp decoder state to escape start and return
|
||||
// continue.
|
||||
this.iso2022jp_decoder_state = states.EscapeStart;
|
||||
return null;
|
||||
}
|
||||
// 0x21 to 0x5F
|
||||
if (utilities_1.inRange(bite, 0x21, 0x5F)) {
|
||||
// Unset the iso-2022-jp output flag and return a code point
|
||||
// whose value is 0xFF61 − 0x21 + byte.
|
||||
this.iso2022jp_output_flag = false;
|
||||
return 0xFF61 - 0x21 + bite;
|
||||
}
|
||||
// end-of-stream
|
||||
if (bite === terminology_1.end_of_stream) {
|
||||
// Return finished.
|
||||
return finished_1.finished;
|
||||
}
|
||||
// Otherwise
|
||||
// Unset the iso-2022-jp output flag and return error.
|
||||
this.iso2022jp_output_flag = false;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
case states.LeadByte:
|
||||
// Lead byte
|
||||
// Based on byte:
|
||||
// 0x1B
|
||||
if (bite === 0x1B) {
|
||||
// Set iso-2022-jp decoder state to escape start and return
|
||||
// continue.
|
||||
this.iso2022jp_decoder_state = states.EscapeStart;
|
||||
return null;
|
||||
}
|
||||
// 0x21 to 0x7E
|
||||
if (utilities_1.inRange(bite, 0x21, 0x7E)) {
|
||||
// Unset the iso-2022-jp output flag, set iso-2022-jp lead
|
||||
// to byte, iso-2022-jp decoder state to trail byte, and
|
||||
// return continue.
|
||||
this.iso2022jp_output_flag = false;
|
||||
this.iso2022jp_lead = bite;
|
||||
this.iso2022jp_decoder_state = states.TrailByte;
|
||||
return null;
|
||||
}
|
||||
// end-of-stream
|
||||
if (bite === terminology_1.end_of_stream) {
|
||||
// Return finished.
|
||||
return finished_1.finished;
|
||||
}
|
||||
// Otherwise
|
||||
// Unset the iso-2022-jp output flag and return error.
|
||||
this.iso2022jp_output_flag = false;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
case states.TrailByte:
|
||||
// Trail byte
|
||||
// Based on byte:
|
||||
// 0x1B
|
||||
if (bite === 0x1B) {
|
||||
// Set iso-2022-jp decoder state to escape start and return
|
||||
// continue.
|
||||
this.iso2022jp_decoder_state = states.EscapeStart;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 0x21 to 0x7E
|
||||
if (utilities_1.inRange(bite, 0x21, 0x7E)) {
|
||||
// 1. Set the iso-2022-jp decoder state to lead byte.
|
||||
this.iso2022jp_decoder_state = states.LeadByte;
|
||||
// 2. Let pointer be (iso-2022-jp lead − 0x21) × 94 + byte − 0x21.
|
||||
var pointer = (this.iso2022jp_lead - 0x21) * 94 + bite - 0x21;
|
||||
// 3. Let code point be the index code point for pointer in
|
||||
// index jis0208.
|
||||
var code_point = indexes_1.indexCodePointFor(pointer, indexes_1.index('jis0208'));
|
||||
// 4. If code point is null, return error.
|
||||
if (code_point === null)
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
// 5. Return a code point whose value is code point.
|
||||
return code_point;
|
||||
}
|
||||
// end-of-stream
|
||||
if (bite === terminology_1.end_of_stream) {
|
||||
// Set the iso-2022-jp decoder state to lead byte, prepend
|
||||
// byte to stream, and return error.
|
||||
this.iso2022jp_decoder_state = states.LeadByte;
|
||||
stream.prepend(bite);
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// Otherwise
|
||||
// Set iso-2022-jp decoder state to lead byte and return
|
||||
// error.
|
||||
this.iso2022jp_decoder_state = states.LeadByte;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
case states.EscapeStart:
|
||||
// Escape start
|
||||
// 1. If byte is either 0x24 or 0x28, set iso-2022-jp lead to
|
||||
// byte, iso-2022-jp decoder state to escape, and return
|
||||
// continue.
|
||||
if (bite === 0x24 || bite === 0x28) {
|
||||
this.iso2022jp_lead = bite;
|
||||
this.iso2022jp_decoder_state = states.Escape;
|
||||
return null;
|
||||
}
|
||||
// 2. Prepend byte to stream.
|
||||
stream.prepend(bite);
|
||||
// 3. Unset the iso-2022-jp output flag, set iso-2022-jp
|
||||
// decoder state to iso-2022-jp decoder output state, and
|
||||
// return error.
|
||||
this.iso2022jp_output_flag = false;
|
||||
this.iso2022jp_decoder_state = this.iso2022jp_decoder_output_state;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
case states.Escape:
|
||||
// Escape
|
||||
// 1. Let lead be iso-2022-jp lead and set iso-2022-jp lead to
|
||||
// 0x00.
|
||||
var lead = this.iso2022jp_lead;
|
||||
this.iso2022jp_lead = 0x00;
|
||||
// 2. Let state be null.
|
||||
var state = null;
|
||||
// 3. If lead is 0x28 and byte is 0x42, set state to ASCII.
|
||||
if (lead === 0x28 && bite === 0x42)
|
||||
state = states.ASCII;
|
||||
// 4. If lead is 0x28 and byte is 0x4A, set state to Roman.
|
||||
if (lead === 0x28 && bite === 0x4A)
|
||||
state = states.Roman;
|
||||
// 5. If lead is 0x28 and byte is 0x49, set state to Katakana.
|
||||
if (lead === 0x28 && bite === 0x49)
|
||||
state = states.Katakana;
|
||||
// 6. If lead is 0x24 and byte is either 0x40 or 0x42, set
|
||||
// state to lead byte.
|
||||
if (lead === 0x24 && (bite === 0x40 || bite === 0x42))
|
||||
state = states.LeadByte;
|
||||
// 7. If state is non-null, run these substeps:
|
||||
if (state !== null) {
|
||||
// 1. Set iso-2022-jp decoder state and iso-2022-jp decoder
|
||||
// output state to states.
|
||||
this.iso2022jp_decoder_state = this.iso2022jp_decoder_state = state;
|
||||
// 2. Let output flag be the iso-2022-jp output flag.
|
||||
var output_flag = this.iso2022jp_output_flag;
|
||||
// 3. Set the iso-2022-jp output flag.
|
||||
this.iso2022jp_output_flag = true;
|
||||
// 4. Return continue, if output flag is unset, and error
|
||||
// otherwise.
|
||||
return !output_flag ? null : encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 8. Prepend lead and byte to stream.
|
||||
stream.prepend([lead, bite]);
|
||||
// 9. Unset the iso-2022-jp output flag, set iso-2022-jp
|
||||
// decoder state to iso-2022-jp decoder output state and
|
||||
// return error.
|
||||
this.iso2022jp_output_flag = false;
|
||||
this.iso2022jp_decoder_state = this.iso2022jp_decoder_output_state;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
};
|
||||
return ISO2022JPDecoder;
|
||||
}());
|
||||
exports.ISO2022JPDecoder = ISO2022JPDecoder;
|
||||
//# sourceMappingURL=ISO2022JPDecoder.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+25
@@ -0,0 +1,25 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
declare enum states {
|
||||
ASCII = 0,
|
||||
Roman = 1,
|
||||
jis0208 = 2
|
||||
}
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class ISO2022JPEncoder {
|
||||
readonly fatal: boolean;
|
||||
iso2022jp_state: states;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
handler(stream: Stream, code_point: number): (number | Array<number>);
|
||||
}
|
||||
export {};
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var states;
|
||||
(function (states) {
|
||||
states[states["ASCII"] = 0] = "ASCII";
|
||||
states[states["Roman"] = 1] = "Roman";
|
||||
states[states["jis0208"] = 2] = "jis0208";
|
||||
})(states || (states = {}));
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var ISO2022JPEncoder = /** @class */ (function () {
|
||||
function ISO2022JPEncoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
// iso-2022-jp's encoder has an associated iso-2022-jp encoder
|
||||
// state which is one of ASCII, Roman, and jis0208 (initially
|
||||
// ASCII).
|
||||
/** @type {number} */ this.iso2022jp_state = states.ASCII;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
ISO2022JPEncoder.prototype.handler = function (stream, code_point) {
|
||||
// 1. If code point is end-of-stream and iso-2022-jp encoder
|
||||
// state is not ASCII, prepend code point to stream, set
|
||||
// iso-2022-jp encoder state to ASCII, and return three bytes
|
||||
// 0x1B 0x28 0x42.
|
||||
if (code_point === terminology_1.end_of_stream &&
|
||||
this.iso2022jp_state !== states.ASCII) {
|
||||
stream.prepend(code_point);
|
||||
this.iso2022jp_state = states.ASCII;
|
||||
return [0x1B, 0x28, 0x42];
|
||||
}
|
||||
// 2. If code point is end-of-stream and iso-2022-jp encoder
|
||||
// state is ASCII, return finished.
|
||||
if (code_point === terminology_1.end_of_stream && this.iso2022jp_state === states.ASCII)
|
||||
return finished_1.finished;
|
||||
// 3. If ISO-2022-JP encoder state is ASCII or Roman, and code
|
||||
// point is U+000E, U+000F, or U+001B, return error with U+FFFD.
|
||||
if ((this.iso2022jp_state === states.ASCII ||
|
||||
this.iso2022jp_state === states.Roman) &&
|
||||
(code_point === 0x000E || code_point === 0x000F ||
|
||||
code_point === 0x001B)) {
|
||||
return encodings_1.encoderError(0xFFFD);
|
||||
}
|
||||
// 4. If iso-2022-jp encoder state is ASCII and code point is an
|
||||
// ASCII code point, return a byte whose value is code point.
|
||||
if (this.iso2022jp_state === states.ASCII &&
|
||||
terminology_1.isASCIICodePoint(code_point))
|
||||
return code_point;
|
||||
// 5. If iso-2022-jp encoder state is Roman and code point is an
|
||||
// ASCII code point, excluding U+005C and U+007E, or is U+00A5
|
||||
// or U+203E, run these substeps:
|
||||
if (this.iso2022jp_state === states.Roman &&
|
||||
((terminology_1.isASCIICodePoint(code_point) &&
|
||||
code_point !== 0x005C && code_point !== 0x007E) ||
|
||||
(code_point == 0x00A5 || code_point == 0x203E))) {
|
||||
// 1. If code point is an ASCII code point, return a byte
|
||||
// whose value is code point.
|
||||
if (terminology_1.isASCIICodePoint(code_point))
|
||||
return code_point;
|
||||
// 2. If code point is U+00A5, return byte 0x5C.
|
||||
if (code_point === 0x00A5)
|
||||
return 0x5C;
|
||||
// 3. If code point is U+203E, return byte 0x7E.
|
||||
if (code_point === 0x203E)
|
||||
return 0x7E;
|
||||
}
|
||||
// 6. If code point is an ASCII code point, and iso-2022-jp
|
||||
// encoder state is not ASCII, prepend code point to stream, set
|
||||
// iso-2022-jp encoder state to ASCII, and return three bytes
|
||||
// 0x1B 0x28 0x42.
|
||||
if (terminology_1.isASCIICodePoint(code_point) &&
|
||||
this.iso2022jp_state !== states.ASCII) {
|
||||
stream.prepend(code_point);
|
||||
this.iso2022jp_state = states.ASCII;
|
||||
return [0x1B, 0x28, 0x42];
|
||||
}
|
||||
// 7. If code point is either U+00A5 or U+203E, and iso-2022-jp
|
||||
// encoder state is not Roman, prepend code point to stream, set
|
||||
// iso-2022-jp encoder state to Roman, and return three bytes
|
||||
// 0x1B 0x28 0x4A.
|
||||
if ((code_point === 0x00A5 || code_point === 0x203E) &&
|
||||
this.iso2022jp_state !== states.Roman) {
|
||||
stream.prepend(code_point);
|
||||
this.iso2022jp_state = states.Roman;
|
||||
return [0x1B, 0x28, 0x4A];
|
||||
}
|
||||
// 8. If code point is U+2212, set it to U+FF0D.
|
||||
if (code_point === 0x2212)
|
||||
code_point = 0xFF0D;
|
||||
// 9. Let pointer be the index pointer for code point in index
|
||||
// jis0208.
|
||||
var pointer = indexes_1.indexPointerFor(code_point, indexes_1.index('jis0208'));
|
||||
// 10. If pointer is null, return error with code point.
|
||||
if (pointer === null)
|
||||
return encodings_1.encoderError(code_point);
|
||||
// 11. If iso-2022-jp encoder state is not jis0208, prepend code
|
||||
// point to stream, set iso-2022-jp encoder state to jis0208,
|
||||
// and return three bytes 0x1B 0x24 0x42.
|
||||
if (this.iso2022jp_state !== states.jis0208) {
|
||||
stream.prepend(code_point);
|
||||
this.iso2022jp_state = states.jis0208;
|
||||
return [0x1B, 0x24, 0x42];
|
||||
}
|
||||
// 12. Let lead be Math.floor(pointer / 94) + 0x21.
|
||||
var lead = Math.floor(pointer / 94) + 0x21;
|
||||
// 13. Let trail be pointer % 94 + 0x21.
|
||||
var trail = pointer % 94 + 0x21;
|
||||
// 14. Return two bytes whose values are lead and trail.
|
||||
return [lead, trail];
|
||||
};
|
||||
return ISO2022JPEncoder;
|
||||
}());
|
||||
exports.ISO2022JPEncoder = ISO2022JPEncoder;
|
||||
//# sourceMappingURL=ISO2022JPEncoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ISO2022JPEncoder.js","sourceRoot":"","sources":["../../../../src/coders/iso-2022-jp/ISO2022JPEncoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAAgE;AAChE,0DAA6E;AAG7E,IAAK,MAIJ;AAJD,WAAK,MAAM;IACT,qCAAK,CAAA;IACL,qCAAK,CAAA;IACL,yCAAO,CAAA;AACT,CAAC,EAJI,MAAM,KAAN,MAAM,QAIV;AAED;;;;GAIG;AACH;IAME,0BAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,8DAA8D;QAC9D,6DAA6D;QAC7D,UAAU;QACV,qBAAqB,CAAC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC;IAC5D,CAAC;IAED;;;;OAIG;IACH,kCAAO,GAAP,UAAQ,MAAc,EAAE,UAAkB;QACxC,4DAA4D;QAC5D,wDAAwD;QACxD,6DAA6D;QAC7D,kBAAkB;QAClB,IAAI,UAAU,KAAK,2BAAa;YAC9B,IAAI,CAAC,eAAe,KAAK,MAAM,CAAC,KAAK,EAAE;YACvC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC3B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC;YACpC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;SAC3B;QAED,4DAA4D;QAC5D,mCAAmC;QACn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AwD;QACxD,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IACH,uBAAC;AAAD,CAAC,AA7HD,IA6HC;AA7HY,4CAAgB"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './ISO2022JPDecoder';
|
||||
export * from './ISO2022JPEncoder';
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./ISO2022JPDecoder"));
|
||||
__export(require("./ISO2022JPEncoder"));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/iso-2022-jp/index.ts"],"names":[],"mappings":";;;;;AAAA,wCAAmC;AACnC,wCAAmC"}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class ShiftJISDecoder {
|
||||
readonly fatal: boolean;
|
||||
Shift_JIS_lead: number;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
handler(stream: Stream, bite: number): (number | Array<number>) | null;
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var ShiftJISDecoder = /** @class */ (function () {
|
||||
function ShiftJISDecoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
// Shift_JIS's decoder has an associated Shift_JIS lead (initially
|
||||
// 0x00).
|
||||
/** @type {number} */ this.Shift_JIS_lead = 0x00;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
ShiftJISDecoder.prototype.handler = function (stream, bite) {
|
||||
// 1. If byte is end-of-stream and Shift_JIS lead is not 0x00,
|
||||
// set Shift_JIS lead to 0x00 and return error.
|
||||
if (bite === terminology_1.end_of_stream && this.Shift_JIS_lead !== 0x00) {
|
||||
this.Shift_JIS_lead = 0x00;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 2. If byte is end-of-stream and Shift_JIS lead is 0x00,
|
||||
// return finished.
|
||||
if (bite === terminology_1.end_of_stream && this.Shift_JIS_lead === 0x00)
|
||||
return finished_1.finished;
|
||||
// 3. If Shift_JIS lead is not 0x00, let lead be Shift_JIS lead,
|
||||
// let pointer be null, set Shift_JIS lead to 0x00, and then run
|
||||
// these substeps:
|
||||
if (this.Shift_JIS_lead !== 0x00) {
|
||||
var lead = this.Shift_JIS_lead;
|
||||
var pointer = null;
|
||||
this.Shift_JIS_lead = 0x00;
|
||||
// 1. Let offset be 0x40, if byte is less than 0x7F, and 0x41
|
||||
// otherwise.
|
||||
var offset = (bite < 0x7F) ? 0x40 : 0x41;
|
||||
// 2. Let lead offset be 0x81, if lead is less than 0xA0, and
|
||||
// 0xC1 otherwise.
|
||||
var lead_offset = (lead < 0xA0) ? 0x81 : 0xC1;
|
||||
// 3. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80
|
||||
// to 0xFC, inclusive, set pointer to (lead − lead offset) ×
|
||||
// 188 + byte − offset.
|
||||
if (utilities_1.inRange(bite, 0x40, 0x7E) || utilities_1.inRange(bite, 0x80, 0xFC))
|
||||
pointer = (lead - lead_offset) * 188 + bite - offset;
|
||||
// 4. If pointer is in the range 8836 to 10715, inclusive,
|
||||
// return a code point whose value is 0xE000 − 8836 + pointer.
|
||||
if (utilities_1.inRange(pointer, 8836, 10715))
|
||||
return 0xE000 - 8836 + pointer;
|
||||
// 5. Let code point be null, if pointer is null, and the
|
||||
// index code point for pointer in index jis0208 otherwise.
|
||||
var code_point = (pointer === null) ? null :
|
||||
indexes_1.indexCodePointFor(pointer, indexes_1.index('jis0208'));
|
||||
// 6. If code point is null and byte is an ASCII byte, prepend
|
||||
// byte to stream.
|
||||
if (code_point === null && terminology_1.isASCIIByte(bite))
|
||||
stream.prepend(bite);
|
||||
// 7. If code point is null, return error.
|
||||
if (code_point === null)
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
// 8. Return a code point whose value is code point.
|
||||
return code_point;
|
||||
}
|
||||
// 4. If byte is an ASCII byte or 0x80, return a code point
|
||||
// whose value is byte.
|
||||
if (terminology_1.isASCIIByte(bite) || bite === 0x80)
|
||||
return bite;
|
||||
// 5. If byte is in the range 0xA1 to 0xDF, inclusive, return a
|
||||
// code point whose value is 0xFF61 − 0xA1 + byte.
|
||||
if (utilities_1.inRange(bite, 0xA1, 0xDF))
|
||||
return 0xFF61 - 0xA1 + bite;
|
||||
// 6. If byte is in the range 0x81 to 0x9F, inclusive, or 0xE0
|
||||
// to 0xFC, inclusive, set Shift_JIS lead to byte and return
|
||||
// continue.
|
||||
if (utilities_1.inRange(bite, 0x81, 0x9F) || utilities_1.inRange(bite, 0xE0, 0xFC)) {
|
||||
this.Shift_JIS_lead = bite;
|
||||
return null;
|
||||
}
|
||||
// 7. Return error.
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
};
|
||||
return ShiftJISDecoder;
|
||||
}());
|
||||
exports.ShiftJISDecoder = ShiftJISDecoder;
|
||||
//# sourceMappingURL=ShiftJISDecoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ShiftJISDecoder.js","sourceRoot":"","sources":["../../../../src/coders/shift-jis/ShiftJISDecoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAAkE;AAClE,0DAAwE;AACxE,sDAAmD;AAEnD;;;;GAIG;AACH;IAME,yBAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,kEAAkE;QAClE,SAAS;QACT,qBAAqB,CAAC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;IACnD,CAAC;IAED;;;;;;OAMG;IACH,iCAAO,GAAP,UAAS,MAAc,EAAE,IAAY;QACnC,8DAA8D;QAC9D,+CAA+C;QAC/C,IAAI,IAAI,KAAK,2BAAa,IAAI,IAAI,CAAC,cAAc,KAAK,IAAI,EAAE;YAC1D,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;QAED,0DAA0D;QAC1D,mBAAmB;QACnB,IAAI,IAAI,KAAK,2BAAa,IAAI,IAAI,CAAC,cAAc,KAAK,IAAI;YACxD,OAAO,mBAAQ,CAAC;QAElB,gEAAgE;QAChE,gEAAgE;QAChE,kBAAkB;QAClB,IAAI,IAAI,CAAC,cAAc,KAAK,IAAI,EAAE;YAChC,IAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC;YACjC,IAAI,OAAO,GAAW,IAAI,CAAC;YAC3B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAE3B,6DAA6D;YAC7D,aAAa;YACb,IAAM,MAAM,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC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AI,EAAE,IAAI,EAAE,IAAI,CAAC;YAC3B,OAAO,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;QAE9B,8DAA8D;QAC9D,4DAA4D;QAC5D,YAAY;QACZ,IAAI,mBAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,mBAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YAC1D,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,OAAO,IAAI,CAAC;SACb;QAED,mBAAmB;QACnB,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IACH,sBAAC;AAAD,CAAC,AAnGD,IAmGC;AAnGY,0CAAe"}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class ShiftJISEncoder {
|
||||
readonly fatal: boolean;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
handler(stream: Stream, code_point: number): (number | Array<number>);
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var ShiftJISEncoder = /** @class */ (function () {
|
||||
function ShiftJISEncoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
ShiftJISEncoder.prototype.handler = function (stream, code_point) {
|
||||
// 1. If code point is end-of-stream, return finished.
|
||||
if (code_point === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 2. If code point is an ASCII code point or U+0080, return a
|
||||
// byte whose value is code point.
|
||||
if (terminology_1.isASCIICodePoint(code_point) || code_point === 0x0080)
|
||||
return code_point;
|
||||
// 3. If code point is U+00A5, return byte 0x5C.
|
||||
if (code_point === 0x00A5)
|
||||
return 0x5C;
|
||||
// 4. If code point is U+203E, return byte 0x7E.
|
||||
if (code_point === 0x203E)
|
||||
return 0x7E;
|
||||
// 5. If code point is in the range U+FF61 to U+FF9F, inclusive,
|
||||
// return a byte whose value is code point − 0xFF61 + 0xA1.
|
||||
if (utilities_1.inRange(code_point, 0xFF61, 0xFF9F))
|
||||
return code_point - 0xFF61 + 0xA1;
|
||||
// 6. If code point is U+2212, set it to U+FF0D.
|
||||
if (code_point === 0x2212)
|
||||
code_point = 0xFF0D;
|
||||
// 7. Let pointer be the index Shift_JIS pointer for code point.
|
||||
var pointer = indexes_1.indexShiftJISPointerFor(code_point);
|
||||
// 8. If pointer is null, return error with code point.
|
||||
if (pointer === null)
|
||||
return encodings_1.encoderError(code_point);
|
||||
// 9. Let lead be Math.floor(pointer / 188).
|
||||
var lead = Math.floor(pointer / 188);
|
||||
// 10. Let lead offset be 0x81, if lead is less than 0x1F, and
|
||||
// 0xC1 otherwise.
|
||||
var lead_offset = (lead < 0x1F) ? 0x81 : 0xC1;
|
||||
// 11. Let trail be pointer % 188.
|
||||
var trail = pointer % 188;
|
||||
// 12. Let offset be 0x40, if trail is less than 0x3F, and 0x41
|
||||
// otherwise.
|
||||
var offset = (trail < 0x3F) ? 0x40 : 0x41;
|
||||
// 13. Return two bytes whose values are lead + lead offset and
|
||||
// trail + offset.
|
||||
return [lead + lead_offset, trail + offset];
|
||||
};
|
||||
return ShiftJISEncoder;
|
||||
}());
|
||||
exports.ShiftJISEncoder = ShiftJISEncoder;
|
||||
//# sourceMappingURL=ShiftJISEncoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ShiftJISEncoder.js","sourceRoot":"","sources":["../../../../src/coders/shift-jis/ShiftJISEncoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAAiE;AACjE,0DAA6E;AAC7E,sDAAmD;AAEnD;;;;GAIG;AACH;IAIE,yBAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,iCAAO,GAAP,UAAQ,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,2BAAa;YAC9B,OAAO,mBAAQ,CAAC;QAElB,8DAA8D;QAC9D,kCAAkC;QAClC,IAAI,8BAAgB,CAAC,UAAU,CAAC,IAAI,UAAU,KAAK,MAAM;YACvD,OAAO,UAAU,CAAC;QAEpB,gDAAgD;QAChD,IAAI,UAAU,KAAK,MAAM;YACvB,OAAO,IAAI,CAAC;QAEd,gDAAgD;QAChD,IAAI,UAAU,KAAK,MAAM;YACvB,OAAO,IAAI,CAAC;QAEd,gEAAgE;QAChE,2DAA2D;QAC3D,IAAI,mBAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC;YACrC,OAAO,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC;QAEpC,gDAAgD;QAChD,IAAI,UAAU,KAAK,MAAM;YACvB,UAAU,GAAG,MAAM,CAAC;QAEtB,gEAAgE;QAChE,IAAM,OAAO,GAAG,iCAAuB,CAAC,UAAU,CAAC,CAAC;QAEpD,uDAAuD;QACvD,IAAI,OAAO,KAAK,IAAI;YAClB,OAAO,wBAAY,CAAC,UAAU,CAAC,CAAC;QAElC,4CAA4C;QAC5C,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC;QAEvC,8DAA8D;QAC9D,kBAAkB;QAClB,IAAM,WAAW,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAEhD,kCAAkC;QAClC,IAAM,KAAK,GAAG,OAAO,GAAG,GAAG,CAAC;QAE5B,+DAA+D;QAC/D,aAAa;QACb,IAAM,MAAM,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAE5C,+DAA+D;QAC/D,kBAAkB;QAClB,OAAO,CAAC,IAAI,GAAG,WAAW,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;IAC9C,CAAC;IACH,sBAAC;AAAD,CAAC,AAjED,IAiEC;AAjEY,0CAAe"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './ShiftJISDecoder';
|
||||
export * from './ShiftJISEncoder';
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./ShiftJISDecoder"));
|
||||
__export(require("./ShiftJISEncoder"));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/shift-jis/index.ts"],"names":[],"mappings":";;;;;AAAA,uCAAkC;AAClC,uCAAkC"}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {!Array.<number>} index The encoding index.
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class SingleByteDecoder {
|
||||
private readonly index;
|
||||
readonly fatal: boolean;
|
||||
constructor(index: Array<number>, options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
handler(stream: Stream, bite: number): (number | Array<number>) | null;
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {!Array.<number>} index The encoding index.
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var SingleByteDecoder = /** @class */ (function () {
|
||||
function SingleByteDecoder(index, options) {
|
||||
this.index = index;
|
||||
this.fatal = options.fatal;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
SingleByteDecoder.prototype.handler = function (stream, bite) {
|
||||
// 1. If byte is end-of-stream, return finished.
|
||||
if (bite === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 2. If byte is an ASCII byte, return a code point whose value
|
||||
// is byte.
|
||||
if (terminology_1.isASCIIByte(bite))
|
||||
return bite;
|
||||
// 3. Let code point be the index code point for byte − 0x80 in
|
||||
// index single-byte.
|
||||
var code_point = this.index[bite - 0x80];
|
||||
// 4. If code point is null, return error.
|
||||
if (!code_point)
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
// 5. Return a code point whose value is code point.
|
||||
return code_point;
|
||||
};
|
||||
return SingleByteDecoder;
|
||||
}());
|
||||
exports.SingleByteDecoder = SingleByteDecoder;
|
||||
//# sourceMappingURL=SingleByteDecoder.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"SingleByteDecoder.js","sourceRoot":"","sources":["../../../../src/coders/single-byte/SingleByteDecoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,0DAAwE;AAExE;;;;;GAKG;AACH;IAIE,2BAA6B,KAAoB,EAAE,OAA4B;QAAlD,UAAK,GAAL,KAAK,CAAe;QAC/C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,mCAAO,GAAP,UAAQ,MAAc,EAAE,IAAY;QAClC,gDAAgD;QAChD,IAAI,IAAI,KAAK,2BAAa;YACxB,OAAO,mBAAQ,CAAC;QAElB,+DAA+D;QAC/D,WAAW;QACX,IAAI,yBAAW,CAAC,IAAI,CAAC;YACnB,OAAO,IAAI,CAAC;QAEd,+DAA+D;QAC/D,qBAAqB;QACrB,IAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;QAE3C,0CAA0C;QAC1C,IAAI,CAAC,UAAU;YACb,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAElC,oDAAoD;QACpD,OAAO,UAAU,CAAC;IACpB,CAAC;IACH,wBAAC;AAAD,CAAC,AApCD,IAoCC;AApCY,8CAAiB"}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { Stream } from "../../common";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {!Array.<?number>} index The encoding index.
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class SingleByteEncoder {
|
||||
private index;
|
||||
readonly fatal: boolean;
|
||||
constructor(index: (number | null)[], options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
handler(stream: Stream, code_point: number): (number | Array<number>);
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var indexes_1 = require("../../encoding/indexes");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {!Array.<?number>} index The encoding index.
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var SingleByteEncoder = /** @class */ (function () {
|
||||
function SingleByteEncoder(index, options) {
|
||||
this.index = index;
|
||||
this.fatal = options.fatal;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
SingleByteEncoder.prototype.handler = function (stream, code_point) {
|
||||
// 1. If code point is end-of-stream, return finished.
|
||||
if (code_point === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 2. If code point is an ASCII code point, return a byte whose
|
||||
// value is code point.
|
||||
if (terminology_1.isASCIICodePoint(code_point))
|
||||
return code_point;
|
||||
// 3. Let pointer be the index pointer for code point in index
|
||||
// single-byte.
|
||||
var pointer = indexes_1.indexPointerFor(code_point, this.index);
|
||||
// 4. If pointer is null, return error with code point.
|
||||
if (pointer === null)
|
||||
encodings_1.encoderError(code_point);
|
||||
// 5. Return a byte whose value is pointer + 0x80.
|
||||
return pointer + 0x80;
|
||||
};
|
||||
return SingleByteEncoder;
|
||||
}());
|
||||
exports.SingleByteEncoder = SingleByteEncoder;
|
||||
//# sourceMappingURL=SingleByteEncoder.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"SingleByteEncoder.js","sourceRoot":"","sources":["../../../../src/coders/single-byte/SingleByteEncoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAAyD;AACzD,0DAA6E;AAE7E;;;;;GAKG;AACH;IAIE,2BAAoB,KAAwB,EAAE,OAA4B;QAAtD,UAAK,GAAL,KAAK,CAAmB;QAC1C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,mCAAO,GAAP,UAAQ,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,2BAAa;YAC9B,OAAO,mBAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,8BAAgB,CAAC,UAAU,CAAC;YAC9B,OAAO,UAAU,CAAC;QAEpB,8DAA8D;QAC9D,eAAe;QACf,IAAM,OAAO,GAAG,yBAAe,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAExD,uDAAuD;QACvD,IAAI,OAAO,KAAK,IAAI;YAClB,wBAAY,CAAC,UAAU,CAAC,CAAC;QAE3B,kDAAkD;QAClD,OAAO,OAAO,GAAG,IAAI,CAAC;IACxB,CAAC;IACH,wBAAC;AAAD,CAAC,AAlCD,IAkCC;AAlCY,8CAAiB"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './SingleByteDecoder';
|
||||
export * from './SingleByteEncoder';
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./SingleByteDecoder"));
|
||||
__export(require("./SingleByteEncoder"));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/single-byte/index.ts"],"names":[],"mappings":";;;;;AAAA,yCAAoC;AACpC,yCAAoC"}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {boolean} utf16_be True if big-endian, false if little-endian.
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class UTF16Decoder {
|
||||
private utf16_be;
|
||||
readonly fatal: boolean;
|
||||
utf16_lead_byte: any;
|
||||
utf16_lead_surrogate: any;
|
||||
constructor(utf16_be: boolean, options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
handler(stream: Stream, bite: number): (number | Array<number>) | null;
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
var converCodeUnitToBytes_1 = require("./converCodeUnitToBytes");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {boolean} utf16_be True if big-endian, false if little-endian.
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var UTF16Decoder = /** @class */ (function () {
|
||||
function UTF16Decoder(utf16_be, options) {
|
||||
this.utf16_be = utf16_be;
|
||||
this.fatal = options.fatal;
|
||||
/** @type {?number} */ this.utf16_lead_byte = null;
|
||||
/** @type {?number} */ this.utf16_lead_surrogate = null;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
UTF16Decoder.prototype.handler = function (stream, bite) {
|
||||
// 1. If byte is end-of-stream and either utf-16 lead byte or
|
||||
// utf-16 lead surrogate is not null, set utf-16 lead byte and
|
||||
// utf-16 lead surrogate to null, and return error.
|
||||
if (bite === terminology_1.end_of_stream && (this.utf16_lead_byte !== null ||
|
||||
this.utf16_lead_surrogate !== null)) {
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 2. If byte is end-of-stream and utf-16 lead byte and utf-16
|
||||
// lead surrogate are null, return finished.
|
||||
if (bite === terminology_1.end_of_stream && this.utf16_lead_byte === null &&
|
||||
this.utf16_lead_surrogate === null) {
|
||||
return finished_1.finished;
|
||||
}
|
||||
// 3. If utf-16 lead byte is null, set utf-16 lead byte to byte
|
||||
// and return continue.
|
||||
if (this.utf16_lead_byte === null) {
|
||||
this.utf16_lead_byte = bite;
|
||||
return null;
|
||||
}
|
||||
// 4. Let code unit be the result of:
|
||||
var code_unit;
|
||||
if (this.utf16_be) {
|
||||
// utf-16be decoder flag is set
|
||||
// (utf-16 lead byte << 8) + byte.
|
||||
code_unit = (this.utf16_lead_byte << 8) + bite;
|
||||
}
|
||||
else {
|
||||
// utf-16be decoder flag is unset
|
||||
// (byte << 8) + utf-16 lead byte.
|
||||
code_unit = (bite << 8) + this.utf16_lead_byte;
|
||||
}
|
||||
// Then set utf-16 lead byte to null.
|
||||
this.utf16_lead_byte = null;
|
||||
// 5. If utf-16 lead surrogate is not null, let lead surrogate
|
||||
// be utf-16 lead surrogate, set utf-16 lead surrogate to null,
|
||||
// and then run these substeps:
|
||||
if (this.utf16_lead_surrogate !== null) {
|
||||
var lead_surrogate = this.utf16_lead_surrogate;
|
||||
this.utf16_lead_surrogate = null;
|
||||
// 1. If code unit is in the range U+DC00 to U+DFFF,
|
||||
// inclusive, return a code point whose value is 0x10000 +
|
||||
// ((lead surrogate − 0xD800) << 10) + (code unit − 0xDC00).
|
||||
if (utilities_1.inRange(code_unit, 0xDC00, 0xDFFF)) {
|
||||
return 0x10000 + (lead_surrogate - 0xD800) * 0x400 +
|
||||
(code_unit - 0xDC00);
|
||||
}
|
||||
// 2. Prepend the sequence resulting of converting code unit
|
||||
// to bytes using utf-16be decoder flag to stream and return
|
||||
// error.
|
||||
stream.prepend(converCodeUnitToBytes_1.convertCodeUnitToBytes(code_unit, this.utf16_be));
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 6. If code unit is in the range U+D800 to U+DBFF, inclusive,
|
||||
// set utf-16 lead surrogate to code unit and return continue.
|
||||
if (utilities_1.inRange(code_unit, 0xD800, 0xDBFF)) {
|
||||
this.utf16_lead_surrogate = code_unit;
|
||||
return null;
|
||||
}
|
||||
// 7. If code unit is in the range U+DC00 to U+DFFF, inclusive,
|
||||
// return error.
|
||||
if (utilities_1.inRange(code_unit, 0xDC00, 0xDFFF))
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
// 8. Return code point code unit.
|
||||
return code_unit;
|
||||
};
|
||||
return UTF16Decoder;
|
||||
}());
|
||||
exports.UTF16Decoder = UTF16Decoder;
|
||||
//# sourceMappingURL=UTF16Decoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"UTF16Decoder.js","sourceRoot":"","sources":["../../../../src/coders/utf-16/UTF16Decoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,0DAA2D;AAC3D,sDAAmD;AACnD,iEAAiE;AAGjE;;;;;GAKG;AACH;IAOE,sBAAoB,QAAiB,EAAE,OAA4B;QAA/C,aAAQ,GAAR,QAAQ,CAAS;QACnC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QACzB,sBAAsB,CAAC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QACnD,sBA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AC;YAEjC,oDAAoD;YACpD,0DAA0D;YAC1D,4DAA4D;YAC5D,IAAI,mBAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;gBACtC,OAAO,OAAO,GAAG,CAAC,cAAc,GAAG,MAAM,CAAC,GAAG,KAAK;oBAChD,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC;aACxB;YAED,4DAA4D;YAC5D,4DAA4D;YAC5D,SAAS;YACT,MAAM,CAAC,OAAO,CAAC,8CAAsB,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YACjE,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;QAED,+DAA+D;QAC/D,8DAA8D;QAC9D,IAAI,mBAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;YACtC,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAC;YACtC,OAAO,IAAI,CAAC;SACb;QAED,+DAA+D;QAC/D,gBAAgB;QAChB,IAAI,mBAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC;YACpC,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAElC,kCAAkC;QAClC,OAAO,SAAS,CAAC;IACnB,CAAC;IACH,mBAAC;AAAD,CAAC,AA9FD,IA8FC;AA9FY,oCAAY"}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { Stream } from "../../common";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {boolean} utf16_be True if big-endian, false if little-endian.
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class UTF16Encoder {
|
||||
private utf16_be;
|
||||
readonly fatal: boolean;
|
||||
constructor(utf16_be: boolean, options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
handler(stream: Stream, code_point: number): (number | Array<number>);
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
var converCodeUnitToBytes_1 = require("./converCodeUnitToBytes");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {boolean} utf16_be True if big-endian, false if little-endian.
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var UTF16Encoder = /** @class */ (function () {
|
||||
function UTF16Encoder(utf16_be, options) {
|
||||
this.utf16_be = utf16_be;
|
||||
this.fatal = options.fatal;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
UTF16Encoder.prototype.handler = function (stream, code_point) {
|
||||
// 1. If code point is end-of-stream, return finished.
|
||||
if (code_point === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 2. If code point is in the range U+0000 to U+FFFF, inclusive,
|
||||
// return the sequence resulting of converting code point to
|
||||
// bytes using utf-16be encoder flag.
|
||||
if (utilities_1.inRange(code_point, 0x0000, 0xFFFF))
|
||||
return converCodeUnitToBytes_1.convertCodeUnitToBytes(code_point, this.utf16_be);
|
||||
// 3. Let lead be ((code point − 0x10000) >> 10) + 0xD800,
|
||||
// converted to bytes using utf-16be encoder flag.
|
||||
var lead = converCodeUnitToBytes_1.convertCodeUnitToBytes(((code_point - 0x10000) >> 10) + 0xD800, this.utf16_be);
|
||||
// 4. Let trail be ((code point − 0x10000) & 0x3FF) + 0xDC00,
|
||||
// converted to bytes using utf-16be encoder flag.
|
||||
var trail = converCodeUnitToBytes_1.convertCodeUnitToBytes(((code_point - 0x10000) & 0x3FF) + 0xDC00, this.utf16_be);
|
||||
// 5. Return a byte sequence of lead followed by trail.
|
||||
return lead.concat(trail);
|
||||
};
|
||||
return UTF16Encoder;
|
||||
}());
|
||||
exports.UTF16Encoder = UTF16Encoder;
|
||||
//# sourceMappingURL=UTF16Encoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"UTF16Encoder.js","sourceRoot":"","sources":["../../../../src/coders/utf-16/UTF16Encoder.ts"],"names":[],"mappings":";;AACA,oDAAmD;AACnD,0DAA2D;AAC3D,sDAAmD;AACnD,iEAAiE;AAEjE;;;;;GAKG;AACH;IAIE,sBAAoB,QAAiB,EAAE,OAA4B;QAA/C,aAAQ,GAAR,QAAQ,CAAS;QACnC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,8BAAO,GAAP,UAAQ,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,2BAAa;YAC9B,OAAO,mBAAQ,CAAC;QAElB,gEAAgE;QAChE,4DAA4D;QAC5D,qCAAqC;QACrC,IAAI,mBAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC;YACrC,OAAO,8CAAsB,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE3D,0DAA0D;QAC1D,kDAAkD;QAClD,IAAM,IAAI,GAAG,8CAAsB,CACjC,CAAC,CAAC,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE1D,6DAA6D;QAC7D,kDAAkD;QAClD,IAAM,KAAK,GAAG,8CAAsB,CAClC,CAAC,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,KAAK,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE5D,uDAAuD;QACvD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IACH,mBAAC;AAAD,CAAC,AArCD,IAqCC;AArCY,oCAAY"}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* @param {number} code_unit
|
||||
* @param {boolean} utf16be
|
||||
* @return {!Array.<number>} bytes
|
||||
*/
|
||||
export declare function convertCodeUnitToBytes(code_unit: number, utf16be: boolean): Array<number>;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* @param {number} code_unit
|
||||
* @param {boolean} utf16be
|
||||
* @return {!Array.<number>} bytes
|
||||
*/
|
||||
function convertCodeUnitToBytes(code_unit, utf16be) {
|
||||
// 1. Let byte1 be code unit >> 8.
|
||||
var byte1 = code_unit >> 8;
|
||||
// 2. Let byte2 be code unit & 0x00FF.
|
||||
var byte2 = code_unit & 0x00FF;
|
||||
// 3. Then return the bytes in order:
|
||||
// utf-16be flag is set: byte1, then byte2.
|
||||
if (utf16be)
|
||||
return [byte1, byte2];
|
||||
// utf-16be flag is unset: byte2, then byte1.
|
||||
return [byte2, byte1];
|
||||
}
|
||||
exports.convertCodeUnitToBytes = convertCodeUnitToBytes;
|
||||
//# sourceMappingURL=converCodeUnitToBytes.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"converCodeUnitToBytes.js","sourceRoot":"","sources":["../../../../src/coders/utf-16/converCodeUnitToBytes.ts"],"names":[],"mappings":";;AAAA;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,SAAiB,EAAE,OAAgB;IACxE,kCAAkC;IAClC,IAAM,KAAK,GAAG,SAAS,IAAI,CAAC,CAAC;IAE7B,sCAAsC;IACtC,IAAM,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;IAEjC,qCAAqC;IACrC,2CAA2C;IAC3C,IAAI,OAAO;QACT,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxB,6CAA6C;IAC7C,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxB,CAAC;AAbD,wDAaC"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './UTF16Decoder';
|
||||
export * from './UTF16Encoder';
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./UTF16Decoder"));
|
||||
__export(require("./UTF16Encoder"));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/utf-16/index.ts"],"names":[],"mappings":";;;;;AAAA,oCAA+B;AAC/B,oCAA+B"}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class UTF8Decoder {
|
||||
readonly fatal: boolean;
|
||||
utf8_code_point: number;
|
||||
utf8_bytes_seen: number;
|
||||
utf8_bytes_needed: number;
|
||||
utf8_lower_boundary: number;
|
||||
utf8_upper_boundary: number;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
handler(stream: Stream, bite: number): (number | Array<number>) | null;
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var UTF8Decoder = /** @class */ (function () {
|
||||
function UTF8Decoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
// utf-8's decoder's has an associated utf-8 code point, utf-8
|
||||
// bytes seen, and utf-8 bytes needed (all initially 0), a utf-8
|
||||
// lower boundary (initially 0x80), and a utf-8 upper boundary
|
||||
// (initially 0xBF).
|
||||
/** @type {number} */ this.utf8_code_point = 0,
|
||||
/** @type {number} */ this.utf8_bytes_seen = 0,
|
||||
/** @type {number} */ this.utf8_bytes_needed = 0,
|
||||
/** @type {number} */ this.utf8_lower_boundary = 0x80,
|
||||
/** @type {number} */ this.utf8_upper_boundary = 0xBF;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
UTF8Decoder.prototype.handler = function (stream, bite) {
|
||||
// 1. If byte is end-of-stream and utf-8 bytes needed is not 0,
|
||||
// set utf-8 bytes needed to 0 and return error.
|
||||
if (bite === terminology_1.end_of_stream && this.utf8_bytes_needed !== 0) {
|
||||
this.utf8_bytes_needed = 0;
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 2. If byte is end-of-stream, return finished.
|
||||
if (bite === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 3. If utf-8 bytes needed is 0, based on byte:
|
||||
if (this.utf8_bytes_needed === 0) {
|
||||
// 0x00 to 0x7F
|
||||
if (utilities_1.inRange(bite, 0x00, 0x7F)) {
|
||||
// Return a code point whose value is byte.
|
||||
return bite;
|
||||
}
|
||||
// 0xC2 to 0xDF
|
||||
else if (utilities_1.inRange(bite, 0xC2, 0xDF)) {
|
||||
// 1. Set utf-8 bytes needed to 1.
|
||||
this.utf8_bytes_needed = 1;
|
||||
// 2. Set UTF-8 code point to byte & 0x1F.
|
||||
this.utf8_code_point = bite & 0x1F;
|
||||
}
|
||||
// 0xE0 to 0xEF
|
||||
else if (utilities_1.inRange(bite, 0xE0, 0xEF)) {
|
||||
// 1. If byte is 0xE0, set utf-8 lower boundary to 0xA0.
|
||||
if (bite === 0xE0)
|
||||
this.utf8_lower_boundary = 0xA0;
|
||||
// 2. If byte is 0xED, set utf-8 upper boundary to 0x9F.
|
||||
if (bite === 0xED)
|
||||
this.utf8_upper_boundary = 0x9F;
|
||||
// 3. Set utf-8 bytes needed to 2.
|
||||
this.utf8_bytes_needed = 2;
|
||||
// 4. Set UTF-8 code point to byte & 0xF.
|
||||
this.utf8_code_point = bite & 0xF;
|
||||
}
|
||||
// 0xF0 to 0xF4
|
||||
else if (utilities_1.inRange(bite, 0xF0, 0xF4)) {
|
||||
// 1. If byte is 0xF0, set utf-8 lower boundary to 0x90.
|
||||
if (bite === 0xF0)
|
||||
this.utf8_lower_boundary = 0x90;
|
||||
// 2. If byte is 0xF4, set utf-8 upper boundary to 0x8F.
|
||||
if (bite === 0xF4)
|
||||
this.utf8_upper_boundary = 0x8F;
|
||||
// 3. Set utf-8 bytes needed to 3.
|
||||
this.utf8_bytes_needed = 3;
|
||||
// 4. Set UTF-8 code point to byte & 0x7.
|
||||
this.utf8_code_point = bite & 0x7;
|
||||
}
|
||||
// Otherwise
|
||||
else {
|
||||
// Return error.
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// Return continue.
|
||||
return null;
|
||||
}
|
||||
// 4. If byte is not in the range utf-8 lower boundary to utf-8
|
||||
// upper boundary, inclusive, run these substeps:
|
||||
if (!utilities_1.inRange(bite, this.utf8_lower_boundary, this.utf8_upper_boundary)) {
|
||||
// 1. Set utf-8 code point, utf-8 bytes needed, and utf-8
|
||||
// bytes seen to 0, set utf-8 lower boundary to 0x80, and set
|
||||
// utf-8 upper boundary to 0xBF.
|
||||
this.utf8_code_point = this.utf8_bytes_needed = this.utf8_bytes_seen = 0;
|
||||
this.utf8_lower_boundary = 0x80;
|
||||
this.utf8_upper_boundary = 0xBF;
|
||||
// 2. Prepend byte to stream.
|
||||
stream.prepend(bite);
|
||||
// 3. Return error.
|
||||
return encodings_1.decoderError(this.fatal);
|
||||
}
|
||||
// 5. Set utf-8 lower boundary to 0x80 and utf-8 upper boundary
|
||||
// to 0xBF.
|
||||
this.utf8_lower_boundary = 0x80;
|
||||
this.utf8_upper_boundary = 0xBF;
|
||||
// 6. Set UTF-8 code point to (UTF-8 code point << 6) | (byte &
|
||||
// 0x3F)
|
||||
this.utf8_code_point = (this.utf8_code_point << 6) | (bite & 0x3F);
|
||||
// 7. Increase utf-8 bytes seen by one.
|
||||
this.utf8_bytes_seen += 1;
|
||||
// 8. If utf-8 bytes seen is not equal to utf-8 bytes needed,
|
||||
// continue.
|
||||
if (this.utf8_bytes_seen !== this.utf8_bytes_needed)
|
||||
return null;
|
||||
// 9. Let code point be utf-8 code point.
|
||||
var code_point = this.utf8_code_point;
|
||||
// 10. Set utf-8 code point, utf-8 bytes needed, and utf-8 bytes
|
||||
// seen to 0.
|
||||
this.utf8_code_point = this.utf8_bytes_needed = this.utf8_bytes_seen = 0;
|
||||
// 11. Return a code point whose value is code point.
|
||||
return code_point;
|
||||
};
|
||||
return UTF8Decoder;
|
||||
}());
|
||||
exports.UTF8Decoder = UTF8Decoder;
|
||||
//# sourceMappingURL=UTF8Decoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"UTF8Decoder.js","sourceRoot":"","sources":["../../../../src/coders/utf-8/UTF8Decoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,0DAA2D;AAC3D,sDAAmD;AAEnD;;;;GAIG;AACH;IAUE,qBAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE3B,8DAA8D;QAC9D,gE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AY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;QAED,+DAA+D;QAC/D,WAAW;QACX,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;QAChC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;QAEhC,+DAA+D;QAC/D,QAAQ;QACR,IAAI,CAAC,eAAe,GAAG,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;QAEnE,uCAAuC;QACvC,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;QAE1B,6DAA6D;QAC7D,YAAY;QACZ,IAAI,IAAI,CAAC,eAAe,KAAK,IAAI,CAAC,iBAAiB;YACjD,OAAO,IAAI,CAAC;QAEd,yCAAyC;QACzC,IAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC;QAExC,gEAAgE;QAChE,aAAa;QACb,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC;QAEzE,qDAAqD;QACrD,OAAO,UAAU,CAAC;IACpB,CAAC;IACH,kBAAC;AAAD,CAAC,AAhJD,IAgJC;AAhJY,kCAAW"}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class UTF8Encoder {
|
||||
readonly fatal: boolean;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
handler(stream: Stream, code_point: number): (number | Array<number>);
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var UTF8Encoder = /** @class */ (function () {
|
||||
function UTF8Encoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
UTF8Encoder.prototype.handler = function (stream, code_point) {
|
||||
// 1. If code point is end-of-stream, return finished.
|
||||
if (code_point === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 2. If code point is an ASCII code point, return a byte whose
|
||||
// value is code point.
|
||||
if (terminology_1.isASCIICodePoint(code_point))
|
||||
return code_point;
|
||||
// 3. Set count and offset based on the range code point is in:
|
||||
var count, offset;
|
||||
// U+0080 to U+07FF, inclusive:
|
||||
if (utilities_1.inRange(code_point, 0x0080, 0x07FF)) {
|
||||
// 1 and 0xC0
|
||||
count = 1;
|
||||
offset = 0xC0;
|
||||
}
|
||||
// U+0800 to U+FFFF, inclusive:
|
||||
else if (utilities_1.inRange(code_point, 0x0800, 0xFFFF)) {
|
||||
// 2 and 0xE0
|
||||
count = 2;
|
||||
offset = 0xE0;
|
||||
}
|
||||
// U+10000 to U+10FFFF, inclusive:
|
||||
else if (utilities_1.inRange(code_point, 0x10000, 0x10FFFF)) {
|
||||
// 3 and 0xF0
|
||||
count = 3;
|
||||
offset = 0xF0;
|
||||
}
|
||||
// 4. Let bytes be a byte sequence whose first byte is (code
|
||||
// point >> (6 × count)) + offset.
|
||||
var bytes = [(code_point >> (6 * count)) + offset];
|
||||
// 5. Run these substeps while count is greater than 0:
|
||||
while (count > 0) {
|
||||
// 1. Set temp to code point >> (6 × (count − 1)).
|
||||
var temp = code_point >> (6 * (count - 1));
|
||||
// 2. Append to bytes 0x80 | (temp & 0x3F).
|
||||
bytes.push(0x80 | (temp & 0x3F));
|
||||
// 3. Decrease count by one.
|
||||
count -= 1;
|
||||
}
|
||||
// 6. Return bytes bytes, in order.
|
||||
return bytes;
|
||||
};
|
||||
return UTF8Encoder;
|
||||
}());
|
||||
exports.UTF8Encoder = UTF8Encoder;
|
||||
//# sourceMappingURL=UTF8Encoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"UTF8Encoder.js","sourceRoot":"","sources":["../../../../src/coders/utf-8/UTF8Encoder.ts"],"names":[],"mappings":";;AACA,oDAAmD;AACnD,0DAA6E;AAC7E,sDAAmD;AAEnD;;;;GAIG;AACH;IAIE,qBAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,6BAAO,GAAP,UAAQ,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,2BAAa;YAC9B,OAAO,mBAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,8BAAgB,CAAC,UAAU,CAAC;YAC9B,OAAO,UAAU,CAAC;QAEpB,+DAA+D;QAC/D,IAAI,KAAa,EAAE,MAAc,CAAC;QAClC,+BAA+B;QAC/B,IAAI,mBAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;YACvC,aAAa;YACb,KAAK,GAAG,CAAC,CAAC;YACV,MAAM,GAAG,IAAI,CAAC;SACf;QACD,+BAA+B;aAC1B,IAAI,mBAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;YAC5C,aAAa;YACb,KAAK,GAAG,CAAC,CAAC;YACV,MAAM,GAAG,IAAI,CAAC;SACf;QACD,kCAAkC;aAC7B,IAAI,mBAAO,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE;YAC/C,aAAa;YACb,KAAK,GAAG,CAAC,CAAC;YACV,MAAM,GAAG,IAAI,CAAC;SACf;QAED,4DAA4D;QAC5D,kCAAkC;QAClC,IAAM,KAAK,GAAG,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QAErD,uDAAuD;QACvD,OAAO,KAAK,GAAG,CAAC,EAAE;YAEhB,kDAAkD;YAClD,IAAM,IAAI,GAAG,UAAU,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;YAE7C,2CAA2C;YAC3C,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;YAEjC,4BAA4B;YAC5B,KAAK,IAAI,CAAC,CAAC;SACZ;QAED,mCAAmC;QACnC,OAAO,KAAK,CAAC;IACf,CAAC;IACH,kBAAC;AAAD,CAAC,AAhED,IAgEC;AAhEY,kCAAW"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './UTF8Decoder';
|
||||
export * from './UTF8Encoder';
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./UTF8Decoder"));
|
||||
__export(require("./UTF8Encoder"));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/utf-8/index.ts"],"names":[],"mappings":";;;;;AAAA,mCAA8B;AAC9B,mCAA8B"}
|
||||
Generated
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class XUserDefinedDecoder {
|
||||
readonly fatal: boolean;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
handler(stream: Stream, bite: number): (number | Array<number>) | null;
|
||||
}
|
||||
Generated
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var XUserDefinedDecoder = /** @class */ (function () {
|
||||
function XUserDefinedDecoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
XUserDefinedDecoder.prototype.handler = function (stream, bite) {
|
||||
// 1. If byte is end-of-stream, return finished.
|
||||
if (bite === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 2. If byte is an ASCII byte, return a code point whose value
|
||||
// is byte.
|
||||
if (terminology_1.isASCIIByte(bite))
|
||||
return bite;
|
||||
// 3. Return a code point whose value is 0xF780 + byte − 0x80.
|
||||
return 0xF780 + bite - 0x80;
|
||||
};
|
||||
return XUserDefinedDecoder;
|
||||
}());
|
||||
exports.XUserDefinedDecoder = XUserDefinedDecoder;
|
||||
//# sourceMappingURL=XUserDefinedDecoder.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"XUserDefinedDecoder.js","sourceRoot":"","sources":["../../../../src/coders/x-user-defined/XUserDefinedDecoder.ts"],"names":[],"mappings":";;AACA,oDAAmD;AACnD,0DAAwE;AAExE;;;;GAIG;AACH;IAIE,6BAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,qCAAO,GAAP,UAAQ,MAAc,EAAE,IAAY;QAClC,gDAAgD;QAChD,IAAI,IAAI,KAAK,2BAAa;YACxB,OAAO,mBAAQ,CAAC;QAElB,+DAA+D;QAC/D,WAAW;QACX,IAAI,yBAAW,CAAC,IAAI,CAAC;YACnB,OAAO,IAAI,CAAC;QAEd,8DAA8D;QAC9D,OAAO,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAC9B,CAAC;IACH,0BAAC;AAAD,CAAC,AA5BD,IA4BC;AA5BY,kDAAmB"}
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
import { Stream } from "../../common/Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
export declare class XUserDefinedEncoder {
|
||||
readonly fatal: boolean;
|
||||
constructor(options: {
|
||||
fatal: boolean;
|
||||
});
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
handler(stream: Stream, code_point: number): (number | Array<number>);
|
||||
}
|
||||
Generated
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var encodings_1 = require("../../encoding/encodings");
|
||||
var finished_1 = require("../../encoding/finished");
|
||||
var terminology_1 = require("../../encoding/terminology");
|
||||
var utilities_1 = require("../../encoding/utilities");
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
var XUserDefinedEncoder = /** @class */ (function () {
|
||||
function XUserDefinedEncoder(options) {
|
||||
this.fatal = options.fatal;
|
||||
}
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
XUserDefinedEncoder.prototype.handler = function (stream, code_point) {
|
||||
// 1.If code point is end-of-stream, return finished.
|
||||
if (code_point === terminology_1.end_of_stream)
|
||||
return finished_1.finished;
|
||||
// 2. If code point is an ASCII code point, return a byte whose
|
||||
// value is code point.
|
||||
if (terminology_1.isASCIICodePoint(code_point))
|
||||
return code_point;
|
||||
// 3. If code point is in the range U+F780 to U+F7FF, inclusive,
|
||||
// return a byte whose value is code point − 0xF780 + 0x80.
|
||||
if (utilities_1.inRange(code_point, 0xF780, 0xF7FF))
|
||||
return code_point - 0xF780 + 0x80;
|
||||
// 4. Return error with code point.
|
||||
return encodings_1.encoderError(code_point);
|
||||
};
|
||||
return XUserDefinedEncoder;
|
||||
}());
|
||||
exports.XUserDefinedEncoder = XUserDefinedEncoder;
|
||||
//# sourceMappingURL=XUserDefinedEncoder.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"XUserDefinedEncoder.js","sourceRoot":"","sources":["../../../../src/coders/x-user-defined/XUserDefinedEncoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,0DAA6E;AAC7E,sDAAmD;AAEnD;;;;GAIG;AACH;IAIE,6BAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,qCAAO,GAAP,UAAQ,MAAc,EAAE,UAAkB;QACxC,qDAAqD;QACrD,IAAI,UAAU,KAAK,2BAAa;YAC9B,OAAO,mBAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,8BAAgB,CAAC,UAAU,CAAC;YAC9B,OAAO,UAAU,CAAC;QAEpB,gEAAgE;QAChE,2DAA2D;QAC3D,IAAI,mBAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC;YACrC,OAAO,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC;QAEpC,mCAAmC;QACnC,OAAO,wBAAY,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IACH,0BAAC;AAAD,CAAC,AA/BD,IA+BC;AA/BY,kDAAmB"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './XUserDefinedDecoder';
|
||||
export * from './XUserDefinedEncoder';
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./XUserDefinedDecoder"));
|
||||
__export(require("./XUserDefinedEncoder"));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/x-user-defined/index.ts"],"names":[],"mappings":";;;;;AAAA,2CAAsC;AACtC,2CAAsC"}
|
||||
Reference in New Issue
Block a user