Initial commit - Dutchie dispensary scraper

This commit is contained in:
Kelly
2025-11-28 19:45:44 -07:00
commit 5757a8e9bd
23375 changed files with 3788799 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -0,0 +1,93 @@
import { decoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexCodePointFor } from "../../encoding/indexes";
import { end_of_stream, isASCIIByte } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
/**
* @constructor
* @implements {Decoder}
* @param {{fatal: boolean}} options
*/
export class Big5Decoder {
constructor(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.
*/
handler(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 === end_of_stream && this.Big5_lead !== 0x00) {
this.Big5_lead = 0x00;
return decoderError(this.fatal);
}
// 2. If byte is end-of-stream and Big5 lead is 0x00, return
// finished.
if (bite === end_of_stream && this.Big5_lead === 0x00)
return 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) {
const lead = this.Big5_lead;
let pointer = null;
this.Big5_lead = 0x00;
// 1. Let offset be 0x40 if byte is less than 0x7F and 0x62
// otherwise.
const 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 (inRange(bite, 0x40, 0x7E) || 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.
const code_point = (pointer === null) ? null :
indexCodePointFor(pointer, index('big5'));
// 5. If code point is null and byte is an ASCII byte, prepend
// byte to stream.
if (code_point === null && isASCIIByte(bite))
stream.prepend(bite);
// 6. If code point is null, return error.
if (code_point === null)
return 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 (isASCIIByte(bite))
return bite;
// 5. If byte is in the range 0x81 to 0xFE, inclusive, set Big5
// lead to byte and return continue.
if (inRange(bite, 0x81, 0xFE)) {
this.Big5_lead = bite;
return null;
}
// 6. Return error.
return decoderError(this.fatal);
}
}
//# sourceMappingURL=Big5Decoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Big5Decoder.js","sourceRoot":"","sources":["../../../../src/coders/big5/Big5Decoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAA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AC;SACb;QAED,mBAAmB;QACnB,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACF"}

View File

@@ -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>);
}

View File

@@ -0,0 +1,46 @@
import { encoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { indexBig5PointerFor } from "../../encoding/indexes";
import { end_of_stream, isASCIICodePoint } from "../../encoding/terminology";
/**
* @constructor
* @implements {Encoder}
* @param {{fatal: boolean}} options
*/
export class Big5Encoder {
constructor(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.
*/
handler(stream, code_point) {
// 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream)
return finished;
// 2. If code point is an ASCII code point, return a byte whose
// value is code point.
if (isASCIICodePoint(code_point))
return code_point;
// 3. Let pointer be the index Big5 pointer for code point.
const pointer = indexBig5PointerFor(code_point);
// 4. If pointer is null, return error with code point.
if (pointer === null)
return encoderError(code_point);
// 5. Let lead be Math.floor(pointer / 157) + 0x81.
const lead = Math.floor(pointer / 157) + 0x81;
// 6. If lead is less than 0xA1, return error with code point.
if (lead < 0xA1)
return encoderError(code_point);
// 7. Let trail be pointer % 157.
const trail = pointer % 157;
// 8. Let offset be 0x40 if trail is less than 0x3F and 0x62
// otherwise.
const offset = trail < 0x3F ? 0x40 : 0x62;
// Return two bytes whose values are lead and trail + offset.
return [lead, trail + offset];
}
}
//# sourceMappingURL=Big5Encoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Big5Encoder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C,CAAC;IAChC,CAAC;CACF"}

View File

@@ -0,0 +1,2 @@
export * from './Big5Decoder';
export * from './Big5Encoder';

View File

@@ -0,0 +1,3 @@
export * from './Big5Decoder';
export * from './Big5Encoder';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/big5/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}

View File

@@ -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;
}

View File

@@ -0,0 +1,92 @@
import { decoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexCodePointFor } from "../../encoding/indexes";
import { end_of_stream, isASCIIByte } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
/**
* @constructor
* @implements {Decoder}
* @param {{fatal: boolean}} options
*/
export class EUCJPDecoder {
constructor(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.
*/
handler(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 === end_of_stream && this.eucjp_lead !== 0x00) {
this.eucjp_lead = 0x00;
return decoderError(this.fatal);
}
// 2. If byte is end-of-stream and euc-jp lead is 0x00, return
// finished.
if (bite === end_of_stream && this.eucjp_lead === 0x00)
return 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 && 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 && 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) {
const lead = this.eucjp_lead;
this.eucjp_lead = 0x00;
// 1. Let code point be null.
let 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 (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) {
code_point = indexCodePointFor((lead - 0xA1) * 94 + (bite - 0xA1), 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 (!inRange(bite, 0xA1, 0xFE))
stream.prepend(bite);
// 5. If code point is null, return error.
if (code_point === null)
return 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 (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 || inRange(bite, 0xA1, 0xFE)) {
this.eucjp_lead = bite;
return null;
}
// 8. Return error.
return decoderError(this.fatal);
}
}
//# sourceMappingURL=EUCJPDecoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"EUCJPDecoder.js","sourceRoot":"","sources":["../../../../src/coders/euc-jp/EUCJPDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAOvB,YAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE3B,yDAAyD;QACzD,sDAAsD;QACtD,sBAAsB,CAAC,IAAI,CAAC,kBAAkB,GAAG,KAAK;YACtD,qBAAqB,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IAC/C,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,MAAc,EAAE,IAAY;QAClC,+DAA+D;QAC/D,yCAAyC;QACzC,IAAI,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE;YACtD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;QAED,8DAA8D;QAC9D,YAAY;QACZ,IAAI,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI;YACpD,OAAO,QAAQ,CAAC;QAElB,6DA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,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;gBAC5B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAEvB,0CAA0C;YAC1C,IAAI,UAAU,KAAK,IAAI;gBACrB,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAElC,oDAAoD;YACpD,OAAO,UAAU,CAAC;SACnB;QAED,+DAA+D;QAC/D,WAAW;QACX,IAAI,WAAW,CAAC,IAAI,CAAC;YACnB,OAAO,IAAI,CAAC;QAEd,0DAA0D;QAC1D,0DAA0D;QAC1D,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,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,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACF"}

View File

@@ -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>);
}

View File

@@ -0,0 +1,56 @@
import { encoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexPointerFor } from "../../encoding/indexes";
import { end_of_stream, isASCIICodePoint } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
/**
* @constructor
* @implements {Encoder}
* @param {{fatal: boolean}} options
*/
export class EUCJPEncoder {
constructor(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.
*/
handler(stream, code_point) {
// 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream)
return finished;
// 2. If code point is an ASCII code point, return a byte whose
// value is code point.
if (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 (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.
const pointer = indexPointerFor(code_point, index('jis0208'));
// 8. If pointer is null, return error with code point.
if (pointer === null)
return encoderError(code_point);
// 9. Let lead be Math.floor(pointer / 94) + 0xA1.
const lead = Math.floor(pointer / 94) + 0xA1;
// 10. Let trail be pointer % 94 + 0xA1.
const trail = pointer % 94 + 0xA1;
// 11. Return two bytes whose values are lead and trail.
return [lead, trail];
}
}
//# sourceMappingURL=EUCJPEncoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"EUCJPEncoder.js","sourceRoot":"","sources":["../../../../src/coders/euc-jp/EUCJPEncoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAIvB,YAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,aAAa;YAC9B,OAAO,QAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,gBAAgB,CAAC,UAAU,CAAC;YAC9B,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,0DAA0D;QAC1D,iBAAiB;QACjB,IAAI,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC;YACrC,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;QAE5C,gDAAgD;QAChD,IAAI,UAAU,KAAK,MAAM;YACvB,UAAU,GAAG,MAAM,CAAC;QAEtB,8DAA8D;QAC9D,WAAW;QACX,MAAM,OAAO,GAAG,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAa,CAAC,CAAC;QAE1E,uDAAuD;QACvD,IAAI,OAAO,KAAK,IAAI;YAClB,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;QAElC,kDAAkD;QAClD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC;QAE7C,wCAAwC;QACxC,MAAM,KAAK,GAAG,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC;QAElC,wDAAwD;QACxD,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;CACF"}

View File

@@ -0,0 +1,2 @@
export * from './EUCJPDecoder';
export * from './EUCJPEncoder';

View File

@@ -0,0 +1,3 @@
export * from './EUCJPDecoder';
export * from './EUCJPEncoder';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/euc-jp/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}

View File

@@ -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;
}

View File

@@ -0,0 +1,74 @@
import { decoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexCodePointFor } from "../../encoding/indexes";
import { end_of_stream, isASCIIByte } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
/**
* @constructor
* @implements {Decoder}
* @param {{fatal: boolean}} options
*/
export class EUCKRDecoder {
constructor(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.
*/
handler(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 === end_of_stream && this.euckr_lead !== 0) {
this.euckr_lead = 0x00;
return decoderError(this.fatal);
}
// 2. If byte is end-of-stream and euc-kr lead is 0x00, return
// finished.
if (bite === end_of_stream && this.euckr_lead === 0)
return 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) {
const lead = this.euckr_lead;
let 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 (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.
const code_point = (pointer === null)
? null : indexCodePointFor(pointer, index('euc-kr'));
// 3. If code point is null and byte is an ASCII byte, prepend
// byte to stream.
if (pointer === null && isASCIIByte(bite))
stream.prepend(bite);
// 4. If code point is null, return error.
if (code_point === null)
return 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 (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 (inRange(bite, 0x81, 0xFE)) {
this.euckr_lead = bite;
return null;
}
// 6. Return error.
return decoderError(this.fatal);
}
}
//# sourceMappingURL=EUCKRDecoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"EUCKRDecoder.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/EUCKRDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAMvB,YAAY,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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AoD;YACpD,OAAO,UAAU,CAAC;SACnB;QAED,+DAA+D;QAC/D,WAAW;QACX,IAAI,WAAW,CAAC,IAAI,CAAC;YACnB,OAAO,IAAI,CAAC;QAEd,0DAA0D;QAC1D,2CAA2C;QAC3C,IAAI,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,OAAO,IAAI,CAAC;SACb;QAED,mBAAmB;QACnB,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACF"}

View File

@@ -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>);
}

View File

@@ -0,0 +1,41 @@
import { encoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexPointerFor } from "../../encoding/indexes";
import { end_of_stream, isASCIICodePoint } from "../../encoding/terminology";
/**
* @constructor
* @implements {Encoder}
* @param {{fatal: boolean}} options
*/
export class EUCKREncoder {
constructor(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.
*/
handler(stream, code_point) {
// 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream)
return finished;
// 2. If code point is an ASCII code point, return a byte whose
// value is code point.
if (isASCIICodePoint(code_point))
return code_point;
// 3. Let pointer be the index pointer for code point in index
// euc-kr.
const pointer = indexPointerFor(code_point, index('euc-kr'));
// 4. If pointer is null, return error with code point.
if (pointer === null)
return encoderError(code_point);
// 5. Let lead be Math.floor(pointer / 190) + 0x81.
const lead = Math.floor(pointer / 190) + 0x81;
// 6. Let trail be pointer % 190 + 0x41.
const trail = (pointer % 190) + 0x41;
// 7. Return two bytes whose values are lead and trail.
return [lead, trail];
}
}
//# sourceMappingURL=EUCKREncoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"EUCKREncoder.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/EUCKREncoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE7E;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAIvB,YAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,aAAa;YAC9B,OAAO,QAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,gBAAgB,CAAC,UAAU,CAAC;YAC9B,OAAO,UAAU,CAAC;QAEpB,8DAA8D;QAC9D,UAAU;QACV,MAAM,OAAO,GAAG,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAa,CAAC,CAAC;QAEzE,uDAAuD;QACvD,IAAI,OAAO,KAAK,IAAI;YAClB,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;QAElC,mDAAmD;QACnD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;QAE9C,wCAAwC;QACxC,MAAM,KAAK,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;QAErC,uDAAuD;QACvD,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;CACF"}

View File

@@ -0,0 +1,2 @@
export * from './EUCKRDecoder';
export * from './EUCKREncoder';

View File

@@ -0,0 +1,3 @@
export * from './EUCKRDecoder';
export * from './EUCKREncoder';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}

View File

@@ -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;
}

View File

@@ -0,0 +1,142 @@
import { decoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexCodePointFor, indexGB18030RangesCodePointFor } from "../../encoding/indexes";
import { end_of_stream, isASCIIByte } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
/**
* @constructor
* @implements {Decoder}
* @param {{fatal: boolean}} options
*/
export class GB18030Decoder {
constructor(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.
*/
handler(stream, bite) {
// 1. If byte is end-of-stream and gb18030 first, gb18030
// second, and gb18030 third are 0x00, return finished.
if (bite === end_of_stream && this.gb18030_first === 0x00 &&
this.gb18030_second === 0x00 && this.gb18030_third === 0x00) {
return 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 === 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;
decoderError(this.fatal);
}
let 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 (inRange(bite, 0x30, 0x39)) {
code_point = 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.
const 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 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 (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 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 (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.
const lead = this.gb18030_first;
let pointer = null;
this.gb18030_first = 0x00;
// 3. Let offset be 0x40 if byte is less than 0x7F and 0x41
// otherwise.
const 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 (inRange(bite, 0x40, 0x7E) || 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 :
indexCodePointFor(pointer, index('gb18030'));
// 6. If code point is null and byte is an ASCII byte, prepend
// byte to stream.
if (code_point === null && isASCIIByte(bite))
stream.prepend(bite);
// 7. If code point is null, return error.
if (code_point === null)
return 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 (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 (inRange(bite, 0x81, 0xFE)) {
this.gb18030_first = bite;
return null;
}
// 9. Return error.
return decoderError(this.fatal);
}
}
//# sourceMappingURL=GB18030Decoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GB18030Decoder.js","sourceRoot":"","sources":["../../../../src/coders/gb18030/GB18030Decoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,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3D,8DAA8D;YAC9D,kBAAkB;YAClB,IAAI,UAAU,KAAK,IAAI,IAAI,WAAW,CAAC,IAAI,CAAC;gBAC1C,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACvB,0CAA0C;YAC1C,IAAI,UAAU,KAAK,IAAI;gBACrB,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClC,oDAAoD;YACpD,OAAO,UAAU,CAAC;SACnB;QACD,+DAA+D;QAC/D,WAAW;QACX,IAAI,WAAW,CAAC,IAAI,CAAC;YACnB,OAAO,IAAI,CAAC;QACd,gDAAgD;QAChD,IAAI,IAAI,KAAK,IAAI;YACf,OAAO,MAAM,CAAC;QAChB,0DAA0D;QAC1D,6CAA6C;QAC7C,IAAI,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YAC7B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAC1B,OAAO,IAAI,CAAC;SACb;QACD,mBAAmB;QACnB,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACF"}

View File

@@ -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>);
}

View File

@@ -0,0 +1,77 @@
import { encoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexGB18030RangesPointerFor, indexPointerFor } from "../../encoding/indexes";
import { end_of_stream, isASCIICodePoint } from "../../encoding/terminology";
/**
* @constructor
* @implements {Encoder}
* @param {{fatal: boolean}} options
* @param {boolean=} gbk_flag
*/
export class GB18030Encoder {
constructor(options, 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.
*/
handler(stream, code_point) {
// 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream)
return finished;
// 2. If code point is an ASCII code point, return a byte whose
// value is code point.
if (isASCIICodePoint(code_point))
return code_point;
// 3. If code point is U+E5E5, return error with code point.
if (code_point === 0xE5E5)
return 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.
let pointer = indexPointerFor(code_point, index('gb18030'));
// 6. If pointer is not null, run these substeps:
if (pointer !== null) {
// 1. Let lead be Math.floor(pointer / 190) + 0x81.
const lead = Math.floor(pointer / 190) + 0x81;
// 2. Let trail be pointer % 190.
const trail = pointer % 190;
// 3. Let offset be 0x40 if trail is less than 0x3F and 0x41 otherwise.
const 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 encoderError(code_point);
// 8. Set pointer to the index gb18030 ranges pointer for code
// point.
pointer = indexGB18030RangesPointerFor(code_point);
// 9. Let byte1 be Math.floor(pointer / 10 / 126 / 10).
const 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).
const 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).
const byte3 = Math.floor(pointer / 10);
// 14. Let byte4 be pointer byte3 × 10.
const 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];
}
}
//# sourceMappingURL=GB18030Encoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GB18030Encoder.js","sourceRoot":"","sources":["../../../../src/coders/gb18030/GB18030Encoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,4BAA4B,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG7E;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IAIzB,YAAY,OAA4B,EAAU,WAAoB,SAAS;QAA7B,aAAQ,GAAR,QAAQ,CAAqB;QAC7E,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,kEAAkE;IACpE,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,aAAa;YAC9B,OAAO,QAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,gBAAgB,CAAC,UAAU,CAAC;YAC9B,OAAO,UAAU,CAAC;QAEpB,4DAA4D;QAC5D,IAAI,UAAU,KAAK,MAAM;YACvB,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;QAElC,6DAA6D;QAC7D,aAAa;QACb,IAAI,IAAI,CAAC,QAAQ,IAAI,UAAU,KAAK,MAAM;YACxC,OAAO,IAAI,CAAC;QAEd,8DAA8D;QAC9D,WAAW;QACX,IAAI,OAAO,GAAG,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAa,CAAC,CA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G,IAAI;YACZ,KAAK,GAAG,IAAI;YACZ,KAAK,GAAG,IAAI,CAAC,CAAC;IAChB,CAAC;CACF"}

View File

@@ -0,0 +1,2 @@
export * from './GB18030Decoder';
export * from './GB18030Encoder';

View File

@@ -0,0 +1,3 @@
export * from './GB18030Decoder';
export * from './GB18030Encoder';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/gb18030/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}

View File

@@ -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;
}

View File

@@ -0,0 +1,268 @@
import { decoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexCodePointFor } from "../../encoding/indexes";
import { end_of_stream } from "../../encoding/terminology";
import { inRange } from "../../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 = {}));
export class ISO2022JPDecoder {
/**
* @constructor
* @implements {Decoder}
* @param {{fatal: boolean}} options
*/
constructor(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.
*/
handler(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 (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 === end_of_stream) {
// Return finished.
return finished;
}
// Otherwise
// Unset the iso-2022-jp output flag and return error.
this.iso2022jp_output_flag = false;
return 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 (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 === end_of_stream) {
// Return finished.
return finished;
}
// Otherwise
// Unset the iso-2022-jp output flag and return error.
this.iso2022jp_output_flag = false;
return 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 (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 === end_of_stream) {
// Return finished.
return finished;
}
// Otherwise
// Unset the iso-2022-jp output flag and return error.
this.iso2022jp_output_flag = false;
return 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 (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 === end_of_stream) {
// Return finished.
return finished;
}
// Otherwise
// Unset the iso-2022-jp output flag and return error.
this.iso2022jp_output_flag = false;
return 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 decoderError(this.fatal);
}
// 0x21 to 0x7E
if (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.
const pointer = (this.iso2022jp_lead - 0x21) * 94 + bite - 0x21;
// 3. Let code point be the index code point for pointer in
// index jis0208.
const code_point = indexCodePointFor(pointer, index('jis0208'));
// 4. If code point is null, return error.
if (code_point === null)
return decoderError(this.fatal);
// 5. Return a code point whose value is code point.
return code_point;
}
// end-of-stream
if (bite === 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 decoderError(this.fatal);
}
// Otherwise
// Set iso-2022-jp decoder state to lead byte and return
// error.
this.iso2022jp_decoder_state = states.LeadByte;
return 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 decoderError(this.fatal);
case states.Escape:
// Escape
// 1. Let lead be iso-2022-jp lead and set iso-2022-jp lead to
// 0x00.
const lead = this.iso2022jp_lead;
this.iso2022jp_lead = 0x00;
// 2. Let state be null.
let 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.
const 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 : 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 decoderError(this.fatal);
}
}
}
//# sourceMappingURL=ISO2022JPDecoder.js.map

File diff suppressed because one or more lines are too long

View File

@@ -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 {};

View File

@@ -0,0 +1,120 @@
import { encoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexPointerFor } from "../../encoding/indexes";
import { end_of_stream, isASCIICodePoint } from "../../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
*/
export class ISO2022JPEncoder {
constructor(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.
*/
handler(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 === 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 === end_of_stream && this.iso2022jp_state === states.ASCII)
return 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 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 &&
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 &&
((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 (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 (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.
const pointer = indexPointerFor(code_point, index('jis0208'));
// 10. If pointer is null, return error with code point.
if (pointer === null)
return 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.
const lead = Math.floor(pointer / 94) + 0x21;
// 13. Let trail be pointer % 94 + 0x21.
const trail = pointer % 94 + 0x21;
// 14. Return two bytes whose values are lead and trail.
return [lead, trail];
}
}
//# sourceMappingURL=ISO2022JPEncoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ISO2022JPEncoder.js","sourceRoot":"","sources":["../../../../src/coders/iso-2022-jp/ISO2022JPEncoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EA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AAK,CAAC;YACpC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;SAC3B;QAED,gDAAgD;QAChD,IAAI,UAAU,KAAK,MAAM;YACvB,UAAU,GAAG,MAAM,CAAC;QAEtB,8DAA8D;QAC9D,WAAW;QACX,MAAM,OAAO,GAAG,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAa,CAAC,CAAC;QAE1E,wDAAwD;QACxD,IAAI,OAAO,KAAK,IAAI;YAClB,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;QAElC,gEAAgE;QAChE,6DAA6D;QAC7D,yCAAyC;QACzC,IAAI,IAAI,CAAC,eAAe,KAAK,MAAM,CAAC,OAAO,EAAE;YAC3C,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC3B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC;YACtC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;SAC3B;QAED,mDAAmD;QACnD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC;QAE7C,wCAAwC;QACxC,MAAM,KAAK,GAAG,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC;QAElC,wDAAwD;QACxD,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;CACF"}

View File

@@ -0,0 +1,2 @@
export * from './ISO2022JPDecoder';
export * from './ISO2022JPEncoder';

View File

@@ -0,0 +1,3 @@
export * from './ISO2022JPDecoder';
export * from './ISO2022JPEncoder';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/iso-2022-jp/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}

View File

@@ -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;
}

View File

@@ -0,0 +1,91 @@
import { decoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexCodePointFor } from "../../encoding/indexes";
import { end_of_stream, isASCIIByte } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
/**
* @constructor
* @implements {Decoder}
* @param {{fatal: boolean}} options
*/
export class ShiftJISDecoder {
constructor(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.
*/
handler(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 === end_of_stream && this.Shift_JIS_lead !== 0x00) {
this.Shift_JIS_lead = 0x00;
return decoderError(this.fatal);
}
// 2. If byte is end-of-stream and Shift_JIS lead is 0x00,
// return finished.
if (bite === end_of_stream && this.Shift_JIS_lead === 0x00)
return 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) {
const lead = this.Shift_JIS_lead;
let pointer = null;
this.Shift_JIS_lead = 0x00;
// 1. Let offset be 0x40, if byte is less than 0x7F, and 0x41
// otherwise.
const offset = (bite < 0x7F) ? 0x40 : 0x41;
// 2. Let lead offset be 0x81, if lead is less than 0xA0, and
// 0xC1 otherwise.
const 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 (inRange(bite, 0x40, 0x7E) || 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 (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.
const code_point = (pointer === null) ? null :
indexCodePointFor(pointer, index('jis0208'));
// 6. If code point is null and byte is an ASCII byte, prepend
// byte to stream.
if (code_point === null && isASCIIByte(bite))
stream.prepend(bite);
// 7. If code point is null, return error.
if (code_point === null)
return 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 (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 (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 (inRange(bite, 0x81, 0x9F) || inRange(bite, 0xE0, 0xFC)) {
this.Shift_JIS_lead = bite;
return null;
}
// 7. Return error.
return decoderError(this.fatal);
}
}
//# sourceMappingURL=ShiftJISDecoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ShiftJISDecoder.js","sourceRoot":"","sources":["../../../../src/coders/shift-jis/ShiftJISDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB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AC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YAC1D,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,OAAO,IAAI,CAAC;SACb;QAED,mBAAmB;QACnB,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACF"}

View File

@@ -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>);
}

View File

@@ -0,0 +1,61 @@
import { encoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { indexShiftJISPointerFor } from "../../encoding/indexes";
import { end_of_stream, isASCIICodePoint } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
/**
* @constructor
* @implements {Encoder}
* @param {{fatal: boolean}} options
*/
export class ShiftJISEncoder {
constructor(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.
*/
handler(stream, code_point) {
// 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream)
return finished;
// 2. If code point is an ASCII code point or U+0080, return a
// byte whose value is code point.
if (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 (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.
const pointer = indexShiftJISPointerFor(code_point);
// 8. If pointer is null, return error with code point.
if (pointer === null)
return encoderError(code_point);
// 9. Let lead be Math.floor(pointer / 188).
const lead = Math.floor(pointer / 188);
// 10. Let lead offset be 0x81, if lead is less than 0x1F, and
// 0xC1 otherwise.
const lead_offset = (lead < 0x1F) ? 0x81 : 0xC1;
// 11. Let trail be pointer % 188.
const trail = pointer % 188;
// 12. Let offset be 0x40, if trail is less than 0x3F, and 0x41
// otherwise.
const offset = (trail < 0x3F) ? 0x40 : 0x41;
// 13. Return two bytes whose values are lead + lead offset and
// trail + offset.
return [lead + lead_offset, trail + offset];
}
}
//# sourceMappingURL=ShiftJISEncoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ShiftJISEncoder.js","sourceRoot":"","sources":["../../../../src/coders/shift-jis/ShiftJISEncoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAI1B,YAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,aAAa;YAC9B,OAAO,QAAQ,CAAC;QAElB,8DAA8D;QAC9D,kCAAkC;QAClC,IAAI,gBAAgB,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,OAAO,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,MAAM,OAAO,GAAG,uBAAuB,CAAC,UAAU,CAAC,CAAC;QAEpD,uDAAuD;QACvD,IAAI,OAAO,KAAK,IAAI;YAClB,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;QAElC,4CAA4C;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC;QAEvC,8DAA8D;QAC9D,kBAAkB;QAClB,MAAM,WAAW,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAEhD,kCAAkC;QAClC,MAAM,KAAK,GAAG,OAAO,GAAG,GAAG,CAAC;QAE5B,+DAA+D;QAC/D,aAAa;QACb,MAAM,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;CACF"}

View File

@@ -0,0 +1,2 @@
export * from './ShiftJISDecoder';
export * from './ShiftJISEncoder';

View File

@@ -0,0 +1,3 @@
export * from './ShiftJISDecoder';
export * from './ShiftJISEncoder';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/shift-jis/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC"}

View File

@@ -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;
}

View File

@@ -0,0 +1,40 @@
import { decoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { end_of_stream, isASCIIByte } from "../../encoding/terminology";
/**
* @constructor
* @implements {Decoder}
* @param {!Array.<number>} index The encoding index.
* @param {{fatal: boolean}} options
*/
export class SingleByteDecoder {
constructor(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.
*/
handler(stream, bite) {
// 1. If byte is end-of-stream, return finished.
if (bite === end_of_stream)
return finished;
// 2. If byte is an ASCII byte, return a code point whose value
// is byte.
if (isASCIIByte(bite))
return bite;
// 3. Let code point be the index code point for byte 0x80 in
// index single-byte.
const code_point = this.index[bite - 0x80];
// 4. If code point is null, return error.
if (!code_point)
return decoderError(this.fatal);
// 5. Return a code point whose value is code point.
return code_point;
}
}
//# sourceMappingURL=SingleByteDecoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SingleByteDecoder.js","sourceRoot":"","sources":["../../../../src/coders/single-byte/SingleByteDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAExE;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IAI5B,YAA6B,KAAoB,EAAE,OAA4B;QAAlD,UAAK,GAAL,KAAK,CAAe;QAC/C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,MAAc,EAAE,IAAY;QAClC,gDAAgD;QAChD,IAAI,IAAI,KAAK,aAAa;YACxB,OAAO,QAAQ,CAAC;QAElB,+DAA+D;QAC/D,WAAW;QACX,IAAI,WAAW,CAAC,IAAI,CAAC;YACnB,OAAO,IAAI,CAAC;QAEd,+DAA+D;QAC/D,qBAAqB;QACrB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;QAE3C,0CAA0C;QAC1C,IAAI,CAAC,UAAU;YACb,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAElC,oDAAoD;QACpD,OAAO,UAAU,CAAC;IACpB,CAAC;CACF"}

View File

@@ -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>);
}

View File

@@ -0,0 +1,39 @@
import { encoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { indexPointerFor } from "../../encoding/indexes";
import { end_of_stream, isASCIICodePoint } from "../../encoding/terminology";
/**
* @constructor
* @implements {Encoder}
* @param {!Array.<?number>} index The encoding index.
* @param {{fatal: boolean}} options
*/
export class SingleByteEncoder {
constructor(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.
*/
handler(stream, code_point) {
// 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream)
return finished;
// 2. If code point is an ASCII code point, return a byte whose
// value is code point.
if (isASCIICodePoint(code_point))
return code_point;
// 3. Let pointer be the index pointer for code point in index
// single-byte.
const pointer = indexPointerFor(code_point, this.index);
// 4. If pointer is null, return error with code point.
if (pointer === null)
encoderError(code_point);
// 5. Return a byte whose value is pointer + 0x80.
return pointer + 0x80;
}
}
//# sourceMappingURL=SingleByteEncoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SingleByteEncoder.js","sourceRoot":"","sources":["../../../../src/coders/single-byte/SingleByteEncoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE7E;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IAI5B,YAAoB,KAAwB,EAAE,OAA4B;QAAtD,UAAK,GAAL,KAAK,CAAmB;QAC1C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,aAAa;YAC9B,OAAO,QAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,gBAAgB,CAAC,UAAU,CAAC;YAC9B,OAAO,UAAU,CAAC;QAEpB,8DAA8D;QAC9D,eAAe;QACf,MAAM,OAAO,GAAG,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAExD,uDAAuD;QACvD,IAAI,OAAO,KAAK,IAAI;YAClB,YAAY,CAAC,UAAU,CAAC,CAAC;QAE3B,kDAAkD;QAClD,OAAO,OAAO,GAAG,IAAI,CAAC;IACxB,CAAC;CACF"}

View File

@@ -0,0 +1,2 @@
export * from './SingleByteDecoder';
export * from './SingleByteEncoder';

View File

@@ -0,0 +1,3 @@
export * from './SingleByteDecoder';
export * from './SingleByteEncoder';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/single-byte/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}

View File

@@ -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;
}

View File

@@ -0,0 +1,93 @@
import { decoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { end_of_stream } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
import { convertCodeUnitToBytes } from "./converCodeUnitToBytes";
/**
* @constructor
* @implements {Decoder}
* @param {boolean} utf16_be True if big-endian, false if little-endian.
* @param {{fatal: boolean}} options
*/
export class UTF16Decoder {
constructor(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.
*/
handler(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 === end_of_stream && (this.utf16_lead_byte !== null ||
this.utf16_lead_surrogate !== null)) {
return 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 === end_of_stream && this.utf16_lead_byte === null &&
this.utf16_lead_surrogate === null) {
return 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:
let 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) {
const 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 (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(convertCodeUnitToBytes(code_unit, this.utf16_be));
return 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 (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 (inRange(code_unit, 0xDC00, 0xDFFF))
return decoderError(this.fatal);
// 8. Return code point code unit.
return code_unit;
}
}
//# sourceMappingURL=UTF16Decoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"UTF16Decoder.js","sourceRoot":"","sources":["../../../../src/coders/utf-16/UTF16Decoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGjE;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAOvB,YAAoB,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,sBAAsB,CAAC,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAC5D,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,MAAc,EAAE,IAAY;QAClC,6DAA6D;QAC7D,8DAA8D;QAC9D,mDAAmD;QACnD,IAAI,IAAI,KAAK,aAAa,IAAI,CAAC,IAAI,CAAC,eAAe,KAAK,IAAI;YAC1D,IAAI,CAAC,oBAAoB,KAAK,IA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AAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YACjE,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;QAED,+DAA+D;QAC/D,8DAA8D;QAC9D,IAAI,OAAO,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,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC;YACpC,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAElC,kCAAkC;QAClC,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}

View File

@@ -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>);
}

View File

@@ -0,0 +1,40 @@
import { finished } from "../../encoding/finished";
import { end_of_stream } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
import { convertCodeUnitToBytes } from "./converCodeUnitToBytes";
/**
* @constructor
* @implements {Encoder}
* @param {boolean} utf16_be True if big-endian, false if little-endian.
* @param {{fatal: boolean}} options
*/
export class UTF16Encoder {
constructor(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.
*/
handler(stream, code_point) {
// 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream)
return 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 (inRange(code_point, 0x0000, 0xFFFF))
return convertCodeUnitToBytes(code_point, this.utf16_be);
// 3. Let lead be ((code point 0x10000) >> 10) + 0xD800,
// converted to bytes using utf-16be encoder flag.
const lead = 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.
const trail = convertCodeUnitToBytes(((code_point - 0x10000) & 0x3FF) + 0xDC00, this.utf16_be);
// 5. Return a byte sequence of lead followed by trail.
return lead.concat(trail);
}
}
//# sourceMappingURL=UTF16Encoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"UTF16Encoder.js","sourceRoot":"","sources":["../../../../src/coders/utf-16/UTF16Encoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAIvB,YAAoB,QAAiB,EAAE,OAA4B;QAA/C,aAAQ,GAAR,QAAQ,CAAS;QACnC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,aAAa;YAC9B,OAAO,QAAQ,CAAC;QAElB,gEAAgE;QAChE,4DAA4D;QAC5D,qCAAqC;QACrC,IAAI,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC;YACrC,OAAO,sBAAsB,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE3D,0DAA0D;QAC1D,kDAAkD;QAClD,MAAM,IAAI,GAAG,sBAAsB,CACjC,CAAC,CAAC,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE1D,6DAA6D;QAC7D,kDAAkD;QAClD,MAAM,KAAK,GAAG,sBAAsB,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;CACF"}

View File

@@ -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>;

View File

@@ -0,0 +1,18 @@
/**
* @param {number} code_unit
* @param {boolean} utf16be
* @return {!Array.<number>} bytes
*/
export function convertCodeUnitToBytes(code_unit, utf16be) {
// 1. Let byte1 be code unit >> 8.
const byte1 = code_unit >> 8;
// 2. Let byte2 be code unit & 0x00FF.
const 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];
}
//# sourceMappingURL=converCodeUnitToBytes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"converCodeUnitToBytes.js","sourceRoot":"","sources":["../../../../src/coders/utf-16/converCodeUnitToBytes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,SAAiB,EAAE,OAAgB;IACxE,kCAAkC;IAClC,MAAM,KAAK,GAAG,SAAS,IAAI,CAAC,CAAC;IAE7B,sCAAsC;IACtC,MAAM,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"}

View File

@@ -0,0 +1,2 @@
export * from './UTF16Decoder';
export * from './UTF16Encoder';

View File

@@ -0,0 +1,3 @@
export * from './UTF16Decoder';
export * from './UTF16Encoder';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/utf-16/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}

View File

@@ -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;
}

View File

@@ -0,0 +1,124 @@
import { decoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { end_of_stream } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
/**
* @constructor
* @implements {Decoder}
* @param {{fatal: boolean}} options
*/
export class UTF8Decoder {
constructor(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.
*/
handler(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 === end_of_stream && this.utf8_bytes_needed !== 0) {
this.utf8_bytes_needed = 0;
return decoderError(this.fatal);
}
// 2. If byte is end-of-stream, return finished.
if (bite === end_of_stream)
return finished;
// 3. If utf-8 bytes needed is 0, based on byte:
if (this.utf8_bytes_needed === 0) {
// 0x00 to 0x7F
if (inRange(bite, 0x00, 0x7F)) {
// Return a code point whose value is byte.
return bite;
}
// 0xC2 to 0xDF
else if (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 (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 (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 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 (!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 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.
const 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;
}
}
//# sourceMappingURL=UTF8Decoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"UTF8Decoder.js","sourceRoot":"","sources":["../../../../src/coders/utf-8/UTF8Decoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAA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Ae,GAAG,CAAC,CAAC;YACzE,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;YAChC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;YAEhC,6BAA6B;YAC7B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAErB,mBAAmB;YACnB,OAAO,YAAY,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,MAAM,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;CACF"}

View File

@@ -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>);
}

View File

@@ -0,0 +1,62 @@
import { finished } from "../../encoding/finished";
import { end_of_stream, isASCIICodePoint } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
/**
* @constructor
* @implements {Encoder}
* @param {{fatal: boolean}} options
*/
export class UTF8Encoder {
constructor(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.
*/
handler(stream, code_point) {
// 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream)
return finished;
// 2. If code point is an ASCII code point, return a byte whose
// value is code point.
if (isASCIICodePoint(code_point))
return code_point;
// 3. Set count and offset based on the range code point is in:
let count, offset;
// U+0080 to U+07FF, inclusive:
if (inRange(code_point, 0x0080, 0x07FF)) {
// 1 and 0xC0
count = 1;
offset = 0xC0;
}
// U+0800 to U+FFFF, inclusive:
else if (inRange(code_point, 0x0800, 0xFFFF)) {
// 2 and 0xE0
count = 2;
offset = 0xE0;
}
// U+10000 to U+10FFFF, inclusive:
else if (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.
const 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)).
const 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;
}
}
//# sourceMappingURL=UTF8Encoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"UTF8Encoder.js","sourceRoot":"","sources":["../../../../src/coders/utf-8/UTF8Encoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA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,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;YAEjC,4BAA4B;YAC5B,KAAK,IAAI,CAAC,CAAC;SACZ;QAED,mCAAmC;QACnC,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}

View File

@@ -0,0 +1,2 @@
export * from './UTF8Decoder';
export * from './UTF8Encoder';

View File

@@ -0,0 +1,3 @@
export * from './UTF8Decoder';
export * from './UTF8Encoder';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/utf-8/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}

View File

@@ -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;
}

View File

@@ -0,0 +1,31 @@
import { finished } from "../../encoding/finished";
import { end_of_stream, isASCIIByte } from "../../encoding/terminology";
/**
* @constructor
* @implements {Decoder}
* @param {{fatal: boolean}} options
*/
export class XUserDefinedDecoder {
constructor(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.
*/
handler(stream, bite) {
// 1. If byte is end-of-stream, return finished.
if (bite === end_of_stream)
return finished;
// 2. If byte is an ASCII byte, return a code point whose value
// is byte.
if (isASCIIByte(bite))
return bite;
// 3. Return a code point whose value is 0xF780 + byte 0x80.
return 0xF780 + bite - 0x80;
}
}
//# sourceMappingURL=XUserDefinedDecoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"XUserDefinedDecoder.js","sourceRoot":"","sources":["../../../../src/coders/x-user-defined/XUserDefinedDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAExE;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAI9B,YAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,MAAc,EAAE,IAAY;QAClC,gDAAgD;QAChD,IAAI,IAAI,KAAK,aAAa;YACxB,OAAO,QAAQ,CAAC;QAElB,+DAA+D;QAC/D,WAAW;QACX,IAAI,WAAW,CAAC,IAAI,CAAC;YACnB,OAAO,IAAI,CAAC;QAEd,8DAA8D;QAC9D,OAAO,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAC9B,CAAC;CACF"}

View File

@@ -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>);
}

View File

@@ -0,0 +1,35 @@
import { encoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { end_of_stream, isASCIICodePoint } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
/**
* @constructor
* @implements {Encoder}
* @param {{fatal: boolean}} options
*/
export class XUserDefinedEncoder {
constructor(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.
*/
handler(stream, code_point) {
// 1.If code point is end-of-stream, return finished.
if (code_point === end_of_stream)
return finished;
// 2. If code point is an ASCII code point, return a byte whose
// value is code point.
if (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 (inRange(code_point, 0xF780, 0xF7FF))
return code_point - 0xF780 + 0x80;
// 4. Return error with code point.
return encoderError(code_point);
}
}
//# sourceMappingURL=XUserDefinedEncoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"XUserDefinedEncoder.js","sourceRoot":"","sources":["../../../../src/coders/x-user-defined/XUserDefinedEncoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAI9B,YAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,MAAc,EAAE,UAAkB;QACxC,qDAAqD;QACrD,IAAI,UAAU,KAAK,aAAa;YAC9B,OAAO,QAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,gBAAgB,CAAC,UAAU,CAAC;YAC9B,OAAO,UAAU,CAAC;QAEpB,gEAAgE;QAChE,2DAA2D;QAC3D,IAAI,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC;YACrC,OAAO,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC;QAEpC,mCAAmC;QACnC,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;CACF"}

View File

@@ -0,0 +1,2 @@
export * from './XUserDefinedDecoder';
export * from './XUserDefinedEncoder';

View File

@@ -0,0 +1,3 @@
export * from './XUserDefinedDecoder';
export * from './XUserDefinedEncoder';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/x-user-defined/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}